Get path of a class

  • Thread starter Florian Lindner
  • Start date
F

Florian Lindner

Hello,
how can I get the path of a class. I managed to do it with

c.__module__ + "." + c.__name__

but I'm sure there is a better way.

Thanks,

Florian
 
P

Peter Hansen

Florian said:
Hello,
how can I get the path of a class. I managed to do it with

c.__module__ + "." + c.__name__

but I'm sure there is a better way.

Please define what you mean by "path" (and how you hope to make use of
this information).

Generally a module has a "path" (i.e. a location where it can be loaded
from the file system) but classes are merely created by "class"
statements within a module. There is no one-to-one match with files,
and in fact no requirement that a class even be traceable directly to
statements in a source file.

-Peter
 
M

Marc 'BlackJack' Rintsch

Hello,
how can I get the path of a class. I managed to do it with

c.__module__ + "." + c.__name__

but I'm sure there is a better way.

How about using the `inspect` module::

In [33]: import inspect, zipfile

In [34]: inspect.getsourcefile(zipfile.ZipInfo)
Out[34]: '/usr/lib/python2.4/zipfile.py'

Ciao,
Marc 'BlackJack' Rintsch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,801
Messages
2,569,658
Members
45,421
Latest member
DoreenCorn

Latest Threads

Top