[Zope] how to use setattr in __init__ method
Nico de Boer
nico@nfg.nl
06 Aug 2002 13:12:15 +0200
Hi all,
I want to clean up my code by setting my arguments dynamically at
initialization. I use the manage_afterAdd method for this, but isn't
there an other way to do this?
This is my code now:
def __init__(self, id, title=''):
"""Initialization Product, a form is added at init"""
self.form = self.init_form()
self.Add_Form()
def manage_afterAdd(self, item, container):
"""magical method"""
for (name, value) in self.REQUEST.form.items():
setattr(self, name, value)
This is my add Form ( in short ):
<dtml-var manage_page_header>
<dtml-var manage_tabs>
<form action="addMail" method="post" enctype="text/html">
<input type="hidden" name="intro" value="">
<input type="hidden" name="subscription" value="">
Id
<input type="text" name="id" size="40" />
Title
<input type="text" name="title" size="40" />
<input class="form-element" type="submit" name="submit" value=" Add ">
</form>
<dtml-var manage_page_footer>
Can't this also be done with:
def __init__( self, id='', **kw ):
"""initialization simple object"""
self.id = id
for (key,value) in kw.items():
setattr(self, key, value)
Greetz Nico