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

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.ca #

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 that attribute is part of the Class

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 I think

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 might not

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 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 foo Cool! I'm