I think you did a typo

it is

def foo2(self, len = self._myvar):
       while i<  len:
         dosomething

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.

Regards
Karim

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
that

class foo(object):

        __init__(self, len = 9):
                self.__myvar = len

        def foo2(self, len = self_myvar):
                while i<  len:
                        dosomething


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?

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to