[Zope] error with setattr

Fernando Martins fmartins@hetnet.nl
Sun, 2 Mar 2003 18:48:44 +0100


> 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