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


Groups > comp.lang.python > #20719

Re: Reset static variables or a workaround

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed20.multikabel.net!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <prvs=3931e6d49=jeanmichel@sequans.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'attributes': 0.05; 'instance,': 0.05; 'passes': 0.05; 'attribute': 0.07; 'instance.': 0.09; 'subclass': 0.09; 'def': 0.13; 'class,': 0.15; 'attribute:': 0.16; 'class:': 0.16; 'guys,': 0.16; 'instances,': 0.16; 'instances.': 0.16; 'instantiated': 0.16; 'name):': 0.16; 'wrote:': 0.18; 'instance': 0.18; 'this?': 0.19; 'cheers,': 0.20; 'to:2**1': 0.21; 'header:In-Reply-To:1': 0.22; 'static': 0.24; 'saying': 0.26; "i'm": 0.28; 'class': 0.29; 'print': 0.29; 'nature.': 0.30; 'values': 0.32; "i've": 0.32; 'header:User- Agent:1': 0.33; 'copied': 0.34; 'to:addr:python-list': 0.35; 'saves': 0.37; 'members': 0.37; 'but': 0.37; 'skip:_ 10': 0.38; 'reset': 0.40; 'user': 0.40; 'to:addr:python.org': 0.40; 'custom': 0.61; '"foo"': 0.84
X-IronPort-AV E=Sophos;i="4.73,469,1325458800"; d="scan'208";a="184552"
X-Virus-Scanned amavisd-new at zimbra.sequans.com
Date Thu, 23 Feb 2012 11:18:07 +0100
From Jean-Michel Pichavant <jeanmichel@sequans.com>
User-Agent Mozilla-Thunderbird 2.0.0.24 (X11/20100328)
MIME-Version 1.0
To Nav <navkirats@gmail.com>, python-list@python.org
Subject Re: Reset static variables or a workaround
References <9a1910c3-ccb0-493a-9756-4c6264e7c3b6@o4g2000pbc.googlegroups.com>
In-Reply-To <9a1910c3-ccb0-493a-9756-4c6264e7c3b6@o4g2000pbc.googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
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.69.1329992297.3037.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1329992297 news.xs4all.nl 6857 [2001:888:2000:d::a6]:45521
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:20719

Show key headers only | View raw


Nav wrote:
> Hi Guys,
>
> I have a custom user form class, it inherits my own custom Form class:
>
> class UserForm(Form):
>     first_name = TextField(attributes={id='id_firstname'})
>
> Now, everytime UserForm() is instantiated it saves the attributes of
> each form members and passes it on to the new instance. 
I'm not sure I've understood this sentence but if you're saying that 
class attributes are  copied into the subclass instance, that's wrong.
> I understand
> this is because first_name is static in nature. But I would like to
> reset the first_name for every instance? How can I do this?
>
> Regards,
> Nav
>   
Class attributes are not default values for instances.
If you want to set the first_name attribute for every instances, you 
have to make it an instance attribute:

class Form:
  def __init__(self):
     self.first_name = "foo"

class UserForm(Form):
  def __init__(self, name):
    Form.__init__(self)
    self.first_name = name


uForm = UserForm('banana')
print uForm.first_name

Cheers,

JM

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Reset static variables or a workaround Nav <navkirats@gmail.com> - 2012-02-23 01:26 -0800
  Re: Reset static variables or a workaround Chris Rebert <clp2@rebertia.com> - 2012-02-23 01:43 -0800
  Re: Reset static variables or a workaround Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-02-23 11:18 +0100

csiph-web