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


Groups > comp.lang.python > #10157

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

From Chris Torek <nospam@torek.net>
Newsgroups comp.lang.python
Subject Re: Use self.vars in class.method(parameters, self.vars)
Date 2011-07-22 22:22 +0000
Organization None of the Above
Message-ID <j0ct7301fo4@news7.newsguy.com> (permalink)
References <0ddc2626-7b99-46ee-9974-87439ae09f1e@e40g2000yqn.googlegroups.com>

Show all headers | View raw


In article <0ddc2626-7b99-46ee-9974-87439ae09f1e@e40g2000yqn.googlegroups.com>
caccolangrifata  <caccolangrifata@gmail.com> 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 ...

Others have answered what appears to have been your actual
question.  Here's an example of using an actual "class scope
variable".

(Note: I have a sinus headache, which is probably the source
of some of the weirder names :-) )

class Florg(object):
    _DEFAULT_IPPY = 17

    @classmethod
    def set_default_ippy(cls, ippy):
        cls._DEFAULT_IPPY = ippy

    def __init__(self, name, ippy = None):
        if ippy is None:
            ippy = self.__class__._DEFAULT_IPPY
        self.name = name
        self.ippy = ippy

    def zormonkle(self):
        print('%s ippy = %s' % (self.name, self.ippy))

def example():
    flist = [Florg('first')]
    flist.append(Florg('second'))
    flist.append(Florg('third', 5))
    Florg.set_default_ippy(-4)
    flist.append(Florg('fourth'))
    flist.append(Florg('fifth', 5))

    for florg in flist:
        florg.zormonkle()

if __name__ == '__main__':
    example()
-- 
In-Real-Life: Chris Torek, Wind River Systems
Intel require I note that my opinions are not those of WRS or Intel
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W)  +1 801 277 2603
email: gmail (figure it out)      http://web.torek.net/torek/index.html

Back to comp.lang.python | Previous | NextPrevious 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