get a self data in a method call
David Abrahams
dave at boost-consulting.com
Sun Dec 22 18:31:14 EST 2002
More information about the Python-list mailing list
Sun Dec 22 18:31:14 EST 2002
- Previous message (by thread): get a self data in a method call
- Next message (by thread): get a self data in a method call
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
polux <polux2001 at wanadoo.fr> writes: > I've a class > > class MyClass: > > def __init__(self): > self.data = 123 > > > now, I want to define a method, which would be like that if it were > possible : > > def func(self, data = self.data ) > > but it doesn't work because python does't know yet what "self" is The typical solution is something like this: def func(self, data = None): if data is None: data = self.data If self.data can be None, then make up some private object whose purpose is to denote "unspecified", and substitute that for None. -- David Abrahams dave at boost-consulting.com * http://www.boost-consulting.com Boost support, enhancements, training, and commercial distribution
- Previous message (by thread): get a self data in a method call
- Next message (by thread): get a self data in a method call
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list