Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10098
| Date | 2011-07-22 13:32 +0200 |
|---|---|
| From | Karim <karim.liateni@free.fr> |
| 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.1361.1311334346.1164.python-list@python.org> (permalink) |
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?
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