Use self.vars in class.method(parameters, self.vars)
karim.liateni at free.fr
Fri Jul 22 13:32:15 CEST 2011
I think you did a typo
def foo2(self, len = self._myvar):
while i< len:
You forget '.' dot between self and _myvar
By the way in the function header you have only one '_'
and in the init you have 2 '_'.
Be careful that's not the same variable and behavior in case you want
to access it.
On 07/22/2011 01:12 PM, caccolangrifata wrote:
> I'm very very new with python, and I have some experience with java
> programming, so probably you guys will notice.
> Anyway this is my question:
> I'd like to use class scope vars in method parameter, something like
> class foo(object):
> __init__(self, len = 9):
> self.__myvar = len
> def foo2(self, len = self_myvar):
> while i< len:
> I want to use optional parameter, so i can use
> myfoo = foo() or myfoo = foo(20)
> and also
> foo.foo2(20) or foo.foo2()
> but in def foo2(self, len = self_myvar):
> self is undefined, so:
> How can I do this stuff?
More information about the Python-list