Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10099
| Date | 2011-07-22 13:33 +0200 |
|---|---|
| From | Thomas Jollans <t@jollybox.de> |
| Subject | Re: Use self.vars in class.method(parameters, self.vars) |
| References | <0ddc2626-7b99-46ee-9974-87439ae09f1e@e40g2000yqn.googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1362.1311334382.1164.python-list@python.org> (permalink) |
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.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Use self.vars in class.method(parameters, self.vars) caccolangrifata <caccolangrifata@gmail.com> - 2011-07-22 04:12 -0700
Re: Use self.vars in class.method(parameters, self.vars) Karim <karim.liateni@free.fr> - 2011-07-22 13:32 +0200
Re: Use self.vars in class.method(parameters, self.vars) Thomas Jollans <t@jollybox.de> - 2011-07-22 13:33 +0200
Re: Use self.vars in class.method(parameters, self.vars) caccolangrifata <caccolangrifata@gmail.com> - 2011-07-22 05:02 -0700
Re: Use self.vars in class.method(parameters, self.vars) Thomas Jollans <t@jollybox.de> - 2011-07-22 14:06 +0200
Re: Use self.vars in class.method(parameters, self.vars) "bruno.desthuilliers@gmail.com" <bruno.desthuilliers@gmail.com> - 2011-07-22 08:43 -0700
Re: Use self.vars in class.method(parameters, self.vars) caccolangrifata <caccolangrifata@gmail.com> - 2011-07-22 09:50 -0700
Re: Use self.vars in class.method(parameters, self.vars) Thomas Jollans <t@jollybox.de> - 2011-07-22 20:58 +0200
Re: Use self.vars in class.method(parameters, self.vars) rantingrick <rantingrick@gmail.com> - 2011-07-22 11:38 -0700
Re: Use self.vars in class.method(parameters, self.vars) Thomas Jollans <t@jollybox.de> - 2011-07-22 20:49 +0200
Re: Use self.vars in class.method(parameters, self.vars) John Gordon <gordon@panix.com> - 2011-07-22 19:00 +0000
Re: Use self.vars in class.method(parameters, self.vars) Chris Angelico <rosuav@gmail.com> - 2011-07-23 05:12 +1000
Re: Use self.vars in class.method(parameters, self.vars) caccolangrifata <caccolangrifata@gmail.com> - 2011-07-22 12:41 -0700
Re: Use self.vars in class.method(parameters, self.vars) rantingrick <rantingrick@gmail.com> - 2011-07-22 12:16 -0700
Re: Use self.vars in class.method(parameters, self.vars) Chris Angelico <rosuav@gmail.com> - 2011-07-23 06:20 +1000
Re: Use self.vars in class.method(parameters, self.vars) Karim <karim.liateni@free.fr> - 2011-07-22 18:54 +0200
Re: Use self.vars in class.method(parameters, self.vars) caccolangrifata <caccolangrifata@gmail.com> - 2011-07-22 09:59 -0700
Re: Use self.vars in class.method(parameters, self.vars) Karim <karim.liateni@free.fr> - 2011-07-22 19:26 +0200
Re: Use self.vars in class.method(parameters, self.vars) Chris Torek <nospam@torek.net> - 2011-07-22 22:22 +0000
csiph-web