determining fully qualified package & class name

P

patrimith

Hi List,

I am used to the following with Java:

import some.package.MyClass;
name = MyClass.class.getName();

The value for name will be "some.package.MyClass".

For Python, I find:

from some.package.myclass import MyClass
name = MyClass.__name__

The value for name will be "MyClass"

Is there a comparable way to get the fully qualified name (package, module,
and class name) in Python?

Thanks,
Patrick Smith
 
M

Marc 'BlackJack' Rintsch

I am used to the following with Java:

import some.package.MyClass;
name = MyClass.class.getName();

The value for name will be "some.package.MyClass".

For Python, I find:

from some.package.myclass import MyClass
name = MyClass.__name__

The value for name will be "MyClass"

Is there a comparable way to get the fully qualified name (package, module,
and class name) in Python?

Take a look at the `__module__` attribute of the class.

Ciao,
Marc 'BlackJack' Rintsch
 
G

Goldfish

import myPackage

f = myPackage.foo()

print f.__module__ + "." + f.__class__.__name__

That should do it!
 

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,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top