[Zope] Re: error with setattr

Maik Jablonski maik.jablonski@uni-bielefeld.de
Sun, 02 Mar 2003 19:17:50 +0100


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/