Re: [Tutor] Question about classes

2007-08-25 Thread Kent Johnson
Ara Kooser wrote: > Hello all, > >I am working on trying to understand classes by creating a > character generator for a rpg. I know I am doing something silly but I > am not sure what. This is a procedural program wrapped in a class declaration. Just get rid of "class Main:" and outdent ev

Re: [Tutor] Question about classes

2007-08-25 Thread Alan Gauld
"Eric Abrahamsen" <[EMAIL PROTECTED]> wrote >> Welcome to the wacky world of recursion. >> You call __upp from inside __upp so you do indeed generate >> a new layer, in fact you start a new while loop. You need to > > So all those "yes"s were actually backing out of multiple while > loops... Shoul

Re: [Tutor] Question about classes

2007-08-25 Thread Eric Abrahamsen
> Welcome to the wacky world of recursion. > You call __upp from inside __upp so you do indeed generate > a new layer, in fact you start a new while loop. You need to > move the while loop out into init, something like this: So all those "yes"s were actually backing out of multiple while loops..

Re: [Tutor] Question about classes

2007-08-25 Thread Alan Gauld
"Eric Abrahamsen" <[EMAIL PROTECTED]> wrote > The new problem is the while loop inside __upp. Every time I say > "no", and it generates a new set of attributes, it seems to add > another "layer" of unfinished = True, so that once I've got > attributes I like, I need to say "yes" as many times as

Re: [Tutor] Question about classes

2007-08-25 Thread Eric Abrahamsen
On Aug 25, 2007, at 12:59 PM, Ara Kooser wrote: > Hello all, > >I am working on trying to understand classes by creating a > character generator for a rpg. I know I am doing something silly but I > am not sure what. When I run the program I and type no when prompted I > get the following messa

Re: [Tutor] Question about classes

2007-08-25 Thread Alan Gauld
"Ara Kooser" <[EMAIL PROTECTED]> wrote > I am working on trying to understand classes by creating a > character generator for a rpg. You are so ar off base at the moment that I suggest you go back to basics and try a much simpler class. Your MAIN is not really a class at all, it's a function

Re: [Tutor] Question about classes

2007-08-24 Thread Noufal Ibrahim
Ara Kooser wrote: > Hello all, > >I am working on trying to understand classes by creating a > character generator for a rpg. I know I am doing something silly but I > am not sure what. When I run the program I and type no when prompted I > get the following message: > Traceback (most recent c

[Tutor] Question about classes

2007-08-24 Thread Ara Kooser
Hello all, I am working on trying to understand classes by creating a character generator for a rpg. I know I am doing something silly but I am not sure what. When I run the program I and type no when prompted I get the following message: Traceback (most recent call last): File "/Users/ara/Do

Re: [Tutor] question about classes and atributes

2006-11-03 Thread Alan Gauld
"Kent Johnson" <[EMAIL PROTECTED]> wrote > Alan Gauld wrote: >> I'm not sure about adding methods at run time, I've never > Sure it works: > > In [1]: class foo(object): pass >...: > In [4]: def show(self): print "Hi, I'm a foo" > > In [5]: foo.show=show > > In [6]: f.show() > Hi, I'm a fo

Re: [Tutor] question about classes and atributes

2006-11-03 Thread euoar
Thank you folks, for your excellent answers. This is really a fantastic place to learn python :-) __ LLama Gratis a cualquier PC del Mundo. Llamadas a fijos y móviles desde 1 céntimo por minuto. http://es.voice.yahoo.com

Re: [Tutor] question about classes and atributes

2006-11-03 Thread Kent Johnson
Alan Gauld wrote: > "euoar" <[EMAIL PROTECTED]> wrote in >> So, in python, you can add methods at run time to an >> object, and even you can add them to a class at run time? > > I'm not sure about adding methods at run time, I've never > tried it but I think the magic around the self parameter

Re: [Tutor] question about classes and atributes

2006-11-03 Thread Alan Gauld
"euoar" <[EMAIL PROTECTED]> wrote in > Thank you for your answer and the examples. > So without self it is an instance variable (like "static" > in java/c#). Without self it is a class attribute like static etc in C++/Java. An instance variable is one that is unique to an instance! Although

Re: [Tutor] question about classes and atributes

2006-11-03 Thread Luke Paireepinart
>>> I think I don't understand the OOP in python, could anyone explain why >>> this code works? >>> >>> class example: >>> atribute = "hello world" >>> >>> print example.atribute >>> >>> Why you don't have to make an object of the class to access to the >>> atribute? >>> because t

Re: [Tutor] question about classes and atributes

2006-11-03 Thread euoar
Andreas Kostyrka escribió: > Because your atribute is a class attribute: > > class C: > ca = 123 > > print C.ca # 123 > c1 = C() > print c1.ca# 123 > c1.ca = 140 > print c1.ca# 140 > print C.ca # 123 > c2 = C() > print c2.ca# 123 > C.ca = 141 > print C.c

Re: [Tutor] question about classes and atributes

2006-11-03 Thread Andreas Kostyrka
Because your atribute is a class attribute: class C: ca = 123 print C.ca # 123 c1 = C() print c1.ca# 123 c1.ca = 140 print c1.ca# 140 print C.ca # 123 c2 = C() print c2.ca# 123 C.ca = 141 print C.ca # 141 print c1.ca# 140 print c2.ca

[Tutor] question about classes and atributes

2006-11-03 Thread euoar
I think I don't understand the OOP in python, could anyone explain why this code works? class example: atribute = "hello world" print example.atribute Why you don't have to make an object of the class to access to the atribute? ( class example: atribute = "hello world" obj