Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Getting class name

Reply
Thread Tools

Getting class name

 
 
Travis Whitton
Guest
Posts: n/a
 
      08-29-2003
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
 
Reply With Quote
 
 
 
 
Michael Hudson
Guest
Posts: n/a
 
      08-29-2003
Travis Whitton <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Eric Brunel
Guest
Posts: n/a
 
      08-29-2003
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 <(E-Mail Removed)> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
adding a variable name to a hash to name is part of the variable name Bobby Chamness Perl 2 04-22-2007 09:54 PM
print("my name is {name}, and {age}-year old {gender}", name, age, gender); =?iso-8859-1?B?bW9vcJk=?= Java 7 01-02-2006 04:39 PM
getting a class if i know the class name Marc E Java 8 11-28-2005 09:00 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
Re: Urgent! how to get object name, method name and attribute name based on the strings? ding feng C++ 2 06-25-2003 01:18 PM



Advertisments