instance vs class attributes

2005-03-29 Thread Sarir Khamsi
I come from a C++ background and am learning some of the details of Python's OO capability and now have some questions. Given: #!/bin/env python class A(object): _x = 10 def __init__(self): self.x = 20 def square(self): return self.x * self.x print 'A.x = %d' % A._x a = A() print 'a.x =

Re: instance vs class attributes

2005-03-29 Thread James Stroud
Sarir said: > Here are my questions: > > 1) What are the benefits of using a member variable without the 'self' >qualifier? (I think this is because you can use _x without an >instance of A().) No such thing as a benefit here. self.a inside a method is the same as a outside (see code belo

Re: instance vs class attributes

2005-03-29 Thread James Stroud
On Tuesday 29 March 2005 05:37 pm, James Stroud wrote: > > 1) What are the benefits of using a member variable without the 'self' > >    qualifier? (I think this is because you can use _x without an > >    instance of A().) > > No such thing as a benefit here. self.a inside a method is the same as

Re: instance vs class attributes

2005-03-29 Thread Brian van den Broek
James Stroud said unto the world upon 2005-03-29 20:37: Sarir said: Here are my questions: 3) Should private data be written as self._x instead of self.x? This is a long standing debate. The usual answer is "we are all grownups here", meaning that self.x is preferred. However, I personally like

Re: instance vs class attributes

2005-03-29 Thread runsun pan
>>> shy._Shy__mangled_method() Ive been mangled! Hi Brian, can you explain how this could possibly work? First of all it's not standard python usage, and secondly it's not working on my computer... pan -- http://mail.python.org/mailman/listinfo/python-list

Re: instance vs class attributes

2005-03-29 Thread James Stroud
You need 2 underscores to mangle. On Tuesday 29 March 2005 09:58 pm, runsun pan wrote: > >>> shy._Shy__mangled_method() > > Ive been mangled! > > > Hi Brian, > > can you explain how this could possibly work? First of all it's not > standard python usage, > and secondly it's not working on my compu