Use self.vars in class.method(parameters, self.vars)
caccolangrifata at gmail.com
Fri Jul 22 14:02:31 CEST 2011
On Jul 22, 1:33 pm, Thomas Jollans <t... at jollybox.de> wrote:
> On 22/07/11 13:12, 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
> > that
> > class foo(object):
> > __init__(self, len = 9):
> > self.__myvar = len
> > def foo2(self, len = self_myvar):
> > while i < len:
> > dosomething
> I think what you want to do is this:
> class foo (object):
> def __init__(self, len=9):
> self._len = len
> def foo2(self, len=None):
> if len is None:
> len = self._len
> # ...
> Default arguments are for when you want to use exactly the same object
> each time the function/method is called. If you the object you want to
> use depends on something, you can use this arg=None idiom.
Yep! Leaving aside the typos, that's exactly I want to do.
More information about the Python-list