determining fully qualified package & class name

Discussion in 'Python' started by patrimith, Oct 11, 2007.

  1. patrimith

    patrimith Guest

    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-fully-qualified-package---class-name-tf4609111.html#a13161736
    Sent from the Python - python-list mailing list archive at Nabble.com.
    patrimith, Oct 11, 2007
    #1
    1. Advertising

  2. 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
    Marc 'BlackJack' Rintsch, Oct 11, 2007
    #2
    1. Advertising

  3. patrimith

    Goldfish Guest

    import myPackage

    f = myPackage.foo()

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

    That should do it!
    Goldfish, Oct 11, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Frank Drebin

    Re: fully qualified domain name

    Frank Drebin, Aug 26, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    549
    Frank Drebin
    Aug 26, 2003
  2. Jim Garrison
    Replies:
    4
    Views:
    1,825
    Peter Flynn
    Oct 27, 2005
  3. Alexander Grigoriev
    Replies:
    0
    Views:
    364
    Alexander Grigoriev
    Sep 12, 2003
  4. Tassilo v. Parseval

    'by package' sorting of fully qualified functions

    Tassilo v. Parseval, Jan 29, 2004, in forum: Perl Misc
    Replies:
    5
    Views:
    85
    Bo Lindbergh
    Jan 29, 2004
  5. Sven-Thorsten Fahrbach
    Replies:
    3
    Views:
    92
    Sven-Thorsten Fahrbach
    Jul 30, 2005
Loading...

Share This Page