Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: Subclasses in Python

Reply
Thread Tools

RE: Subclasses in Python

 
 
Robert Brewer
Guest
Posts: n/a
 
      04-29-2004
Thomas Philips wrote:
> I ... used self.__Class__.<whatever I need to access> to access
> the class attributes in the class and subclass. Works like a charm,
> but I'm having some difficulty printing class names. I want
> self.__class__ to return just the name of the class without some
> ancillary stuff thrown in.


Try self.__class__.__name__


FuManChu

 
Reply With Quote
 
 
 
 
Thomas Philips
Guest
Posts: n/a
 
      04-30-2004
Perfect! But tell me, how did you know to use __name__? I typed
dir(object) and dir(Player) in IDLE, and in neither case did __name__
show up.

>>> dir(object) gives me

['__class__', '__delattr__', '__doc__', '__getattribute__',
'__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__setattr__', '__str__']

dir(Player) gives me a few more things - the object's methods and
class variables, and some additional stuff: __dict__, __hash__,
__module__ and __weakref__. Neither sight nor sound of __name__ -
__module__is as close as I get to the magical __name__. What gives?

And, before I forget, thanks for all the help - I wouldn't have solved
it without you.

Thomas Philips
 
Reply With Quote
 
 
 
 
Greg Ewing
Guest
Posts: n/a
 
      04-30-2004
Thomas Philips wrote:
> Perfect! But tell me, how did you know to use __name__? I typed
> dir(object) and dir(Player) in IDLE, and in neither case did __name__
> show up.


Probably it's an oversight on the part of whoever implemented
the dir() method for classes. I guess you just have to find
out things like that by hanging out in c.l.py.

--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg

 
Reply With Quote
 
Terry Reedy
Guest
Posts: n/a
 
      04-30-2004

"Greg Ewing" <(E-Mail Removed)> wrote in message
news:c6sdiq$fk1bl$(E-Mail Removed)-berlin.de...
> Thomas Philips wrote:
> > Perfect! But tell me, how did you know to use __name__? I typed
> > dir(object) and dir(Player) in IDLE, and in neither case did __name__
> > show up.

>
> Probably it's an oversight on the part of whoever implemented
> the dir() method for classes. I guess you just have to find
> out things like that by hanging out in c.l.py.


And submit a bug report on sourceforge so some future person will find it
with dir().

tjr




 
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
JNDI, Context.OBJECT_FACTORIES, and subclasses Steve Nakhla Java 0 09-27-2004 06:19 PM
Subclasses in Python Thomas Philips Python 5 04-29-2004 05:58 PM
Memory Space Allocation and subclasses Marc Twain Java 2 01-07-2004 11:36 AM
Q on Classes & SubClasses with protected members Praveen Java 1 11-21-2003 03:14 AM
Subclasses in interfaces Bura Tino Java 17 11-07-2003 05:15 AM



Advertisments