default argument
Chris Rebert
clp2 at rebertia.com
Tue May 11 15:20:26 EDT 2010
On Tue, May 11, 2010 at 12:08 PM, Back9 <backgoodoo at gmail.com> wrote:
> On May 11, 3:06 pm, Back9 <backgoo... at gmail.com> wrote:
<snip>
>> When i try it, it complains about undefined self.
>>
>> i don't know why.
>>
>> TIA
>
> Sorry
> here is the what i meant
> class test:
> self._value = 10
> def func(self, pos = self._value)
You're still defining the class, so how could there possibly be an
instance of it to refer to as "self" yet (outside of a method body)?
Also, just so you know, default argument values are only evaluated
once, at the time the function/method is defined, so `pos =
self._value` is never going to work.
Do you mean for self._value to be a class variable (Java lingo: static
variable), or an instance variable?
Cheers,
Chris
--
http://blog.rebertia.com
More information about the Python-list
mailing list