Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33231 > unrolled thread
| Started by | Dave Angel <d@davea.name> |
|---|---|
| First post | 2012-11-13 04:36 -0500 |
| Last post | 2012-11-13 04:36 -0500 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Getting module path string from a class instance Dave Angel <d@davea.name> - 2012-11-13 04:36 -0500
| From | Dave Angel <d@davea.name> |
|---|---|
| Date | 2012-11-13 04:36 -0500 |
| Subject | Re: Getting module path string from a class instance |
| Message-ID | <mailman.3618.1352799412.27098.python-list@python.org> |
On 11/13/2012 01:38 AM, Some Developer wrote: > I'm trying to find a way to get a string of the module path of a class. > > So for instance say I have class Foo and it is in a module called > my.module. I want to be able to get a string that is equal to this: > "my.module.Foo". I'm aware of the __repr__ method but it does not do > what I want it to do in this case. > > Can anyone offer any advice at all? So you have: import my.module theclass = my.module.Foo print tellme(theClass) and you want to know how to write tellme? Why not just change it to take a string, and pass it "my.module.Foo" ? If you have stored the class away somewhere, and want to figure it out from there, you could look at the __module__ attribute. that'll tell you the module name, but not the class name. If you're really asking how to get that string from an INSTANCE of the class, then try the __class__ attribute of that instance. -- DaveA
Back to top | Article view | comp.lang.python
csiph-web