Hi, I tried this simple script (adapted from the Python tutorial): __________________ class Record: pass obj=Record() obj.setattr('field1',1) print obj return printed __________________ and got this error Error Type: AttributeError Error Value: Record instance has no attribute 'setattr' Why is it not working? Fernando
setattr(obj, key, value). -aj --On Sonntag, 2. März 2003 17:08 +0100 Fernando Martins <fmartins@hetnet.nl> wrote:
Hi,
I tried this simple script (adapted from the Python tutorial): __________________ class Record: pass
obj=Record() obj.setattr('field1',1) print obj return printed __________________
and got this error
Error Type: AttributeError Error Value: Record instance has no attribute 'setattr'
Why is it not working?
Fernando
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- --------------------------------------------------------------------- - Andreas Jung http://www.andreas-jung.com - - EMail: andreas at andreas-jung.com - - "Life is too short to (re)write parsers" - ---------------------------------------------------------------------
Andreas Jung wrote: setattr(obj, key, value).
Ah! it's not a method. Somehow I thought obj meant self... Now, I'm getting the error: Error Type: TypeError Error Value: attribute-less object (assign or del) which is correct in the original version, but after adding a dummy field I still get the error. _____________________ class Record: field0 = 0 obj=Record() setattr(obj, 'field1', 1) print obj return printed ______________________ What silly mistake am I doing now? Thanks, Fernando
Fernando Martins wrote:
Andreas Jung wrote: setattr(obj, key, value).
Ah! it's not a method. Somehow I thought obj meant self...
Now, I'm getting the error:
Error Type: TypeError Error Value: attribute-less object (assign or del)
which is correct in the original version, but after adding a dummy field I still get the error.
_____________________ class Record: field0 = 0
obj=Record() setattr(obj, 'field1', 1) print obj return printed ______________________
What silly mistake am I doing now?
If I write class Record: self.field0 = 0 I get the error (on the 2nd line): Error Type: NameError Error Value: name '_write' is not defined What now? This was supposed to be just a simple test to see if I could (and how) to add attributes to a record variable passed from a html form. Fernando
Fernando Martins wrote:
Fernando Martins wrote:
Andreas Jung wrote: setattr(obj, key, value).
Ah! it's not a method. Somehow I thought obj meant self...
Now, I'm getting the error:
Error Type: TypeError Error Value: attribute-less object (assign or del)
which is correct in the original version, but after adding a dummy field I still get the error.
_____________________ class Record: field0 = 0
obj=Record() setattr(obj, 'field1', 1) print obj return printed ______________________
What silly mistake am I doing now?
If I write
class Record: self.field0 = 0
I get the error (on the 2nd line):
Error Type: NameError Error Value: name '_write' is not defined
What now?
This was supposed to be just a simple test to see if I could (and how) to add attributes to a record variable passed from a html form.
Just a guess: Do you use PythonScripts? You can't define classes etc. in PythonScripts. You have to use ExternalMethods or Python-Products... -mj -- Deutsche/German Zope User Group (DZUG) http://www.dzug.org/Members/mjablonski/
Maik Jablonski wrote:
This was supposed to be just a simple test to see if I could (and how) to add attributes to a record variable passed from a html form.
Just a guess: Do you use PythonScripts? You can't define classes etc. in PythonScripts. You have to use ExternalMethods or Python-Products...
Yes, that's it. Thanks. But it also seems I can't use setattr to add an attribute to a PythonScript parameter (which comes from a form)?? I get the error: Error Type: TypeError Error Value: attribute-less object (assign or del) What type of object is a PythonScript parameter? (or how can I test it for myself without a type function?) Fernando
participants (3)
-
Andreas Jung -
Fernando Martins -
Maik Jablonski