[Tutor] Class stuff

R. A. rob@jam.rr.com
Thu, 23 Nov 2000 09:27:48 -0600


I saved your snip of code as Room.py on my 'puter and typed "import
Room" in IDLE.  After making a change to indentation, it ran without
complaint.

Rob A.

Richard Wilkins wrote:
> 
> Hello everyone,
> 
> I'm _positive_ it's a newbie question, so brace yourselves.
> 
> I have a regular old dictionary called Rooms, and a class called Room.
> 
> Room is defined as follows -
> 
> class Room:
>         def __init__(self,x,y,z):
>         self.Position=(x,y,z)
>         self.this=self
>         if Rooms.has_key(str(x)+','+str(y)+','+str(z)):
>                 print 'Room already exists'
>         else:
>                 Rooms[str(x)+','+str(y)+','+str(z)]=self
> 
> When I create an object it all works fine. When I type Rooms at the
> interpreter prompt, it says:
> "call of non-function (type None)"
> 
> I've debugged it down to the last line, so that referencing the class as
> self does not work. I need to know how to reference the class from
> within itself. I don't want to have to provide a function that wraps the
> class...:(
> 
> Can someone please help me with my problem?
> 
> Thanks,
> Andrew Wilkins
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor