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 call
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.
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 message:
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 I said no
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 yess were actually backing out of multiple while
loops...
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 yess were actually backing out of multiple while
loops... Should have guessed
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
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
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 =
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
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.ca #
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 that attribute is part of the Class
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 I think
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
might not
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
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 foo
Cool!
I'm
16 matches
Mail list logo