Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #10098

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

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <karim.liateni@free.fr>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'python,': 0.01; 'anyway': 0.03; 'header:In-reply-to:1': 0.09; 'question:': 0.09; 'subject:parameters': 0.09; 'wrote:': 0.15; 'from:addr:free.fr': 0.16; 'len': 0.16; 'parameter,': 0.16; 'typo': 0.16; 'pm,': 0.16; 'def': 0.16; 'java': 0.21; 'variable': 0.21; 'optional': 0.23; 'function': 0.26; "i'm": 0.27; 'class': 0.31; 'programming,': 0.32; 'it.': 0.33; 'to:addr:python-list': 0.34; 'header:User- Agent:1': 0.34; 'init': 0.35; 'probably': 0.35; 'guys': 0.36; 'some': 0.37; 'but': 0.37; 'subject:: ': 0.38; 'something': 0.38; 'think': 0.38; 'case': 0.39; 'to:addr:python.org': 0.39; 'header': 0.40; 'did': 0.40; "i'd": 0.40; 'forget': 0.61; 'received:62': 0.67; 'so:': 0.84; 'notice.': 0.96
Date Fri, 22 Jul 2011 13:32:15 +0200
From Karim <karim.liateni@free.fr>
Subject Re: Use self.vars in class.method(parameters, self.vars)
In-reply-to <0ddc2626-7b99-46ee-9974-87439ae09f1e@e40g2000yqn.googlegroups.com>
To python-list@python.org
MIME-version 1.0
Content-type text/plain; charset=ISO-8859-1; format=flowed
Content-transfer-encoding 7bit
References <0ddc2626-7b99-46ee-9974-87439ae09f1e@e40g2000yqn.googlegroups.com>
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110617 Thunderbird/3.1.11
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1361.1311334346.1164.python-list@python.org> (permalink)
Lines 45
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1311334346 news.xs4all.nl 23982 [2001:888:2000:d::a6]:45281
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:10098

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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