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: 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 User-Agent: Mozilla-Thunderbird 2.0.0.24 (X11/20100328) MIME-Version: 1.0 To: Nav , 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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