Use self.vars in class.method(parameters, self.vars)

caccolangrifata caccolangrifata at gmail.com
Fri Jul 22 07:12:11 EDT 2011


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?



More information about the Python-list mailing list