471,354 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

determining fully qualified package & class name


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
--
View this message in context: http://www.nabble.com/determining-fu...html#a13161736
Sent from the Python - python-list mailing list archive at Nabble.com.

Oct 11 '07 #1
2 7730
On Thu, 11 Oct 2007 11:18:33 -0700, patrimith wrote:
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
Oct 11 '07 #2
import myPackage

f = myPackage.foo()

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

That should do it!

Oct 11 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Stefan | last post: by
2 posts views Thread by Gravy | last post: by
4 posts views Thread by Aashish Patil | last post: by
5 posts views Thread by fc2 | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.