Getting class name

Discussion in 'Python' started by Travis Whitton, Aug 29, 2003.

  1. Hello all,
    I've googled a bit, and I've failed to find an answer to this question. Is it
    possible to get a classes name from inside of a class? I.e.,

    class Foo:
    def print_classname(self):
    # somehow print Foo

    Basically, I'm using WebWare, and I need to pass the current servlet name
    to a template. I don't want to have to hardcode the classname inside of
    every servlet.

    TIA,
    Travis Whitton
     
    Travis Whitton, Aug 29, 2003
    #1
    1. Advertising

  2. Travis Whitton <> writes:

    > Hello all,
    > I've googled a bit, and I've failed to find an answer to this question. Is it
    > possible to get a classes name from inside of a class? I.e.,
    >
    > class Foo:
    > def print_classname(self):
    > # somehow print Foo


    print self.__class__.__name__

    ?

    Cheers,
    mwh

    --
    MARVIN: Do you want me to sit in a corner and rust, or just fall
    apart where I'm standing?
    -- The Hitch-Hikers Guide to the Galaxy, Episode 2
     
    Michael Hudson, Aug 29, 2003
    #2
    1. Advertising

  3. Travis Whitton

    Eric Brunel Guest

    Travis Whitton wrote:
    > Hello all,
    > I've googled a bit, and I've failed to find an answer to this question. Is it
    > possible to get a classes name from inside of a class? I.e.,
    >
    > class Foo:
    > def print_classname(self):
    > # somehow print Foo
    >
    > Basically, I'm using WebWare, and I need to pass the current servlet name
    > to a template. I don't want to have to hardcode the classname inside of
    > every servlet.


    print self.__class__.__name__

    HTH
    --
    - Eric Brunel <> -
    PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
     
    Eric Brunel, Aug 29, 2003
    #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. E11
    Replies:
    1
    Views:
    4,953
    Thomas Weidenfeller
    Oct 12, 2005
  2. Marc E
    Replies:
    8
    Views:
    414
    Thomas Hawtin
    Nov 28, 2005
  3. =?iso-8859-1?B?bW9vcJk=?=
    Replies:
    7
    Views:
    898
    Roedy Green
    Jan 2, 2006
  4. ding feng
    Replies:
    2
    Views:
    2,916
    ding feng
    Jun 25, 2003
  5. Bobby Chamness
    Replies:
    2
    Views:
    2,446
    Joe Smith
    Apr 22, 2007
Loading...

Share This Page