how to return a new object from a pythonscript ?
Hi, I have a python-script getArtikel, which return items from a ZPatterns-Rack, like so: item=context.getItem("theItemId") return item this works fine, now I want to override some of the attributes of the item: item=context.getItem("theItemId") setattr(item.text,item.text_english) # the attribute text_english exists return item but that results in an error: attributeless object assign or del. I solved that problem by creating a dictionary, and "copying" the attributes into it. but now - of course - my python expressions python: here.getArtikel.date.strftime('%d.%m.%Y') in the pagetemplates complain that there is no attribute "date", and I have to change all those attribute references to here.getArtikel['date'].strftime('%d.%m.%Y') I know that I cannot change object-attributes in scripts. Is there a simple solution for this ? Or is it simply not possible ? Mit freundlichen Grüßen Joachim Schmitz -------------------------------------------------------------------- AixtraWare Ingenieurbüro für Internetanwendungen Hüsgenstr. 33a, D-52457 Aldenhoven Telefon: +49-2464-8851, FAX: +49-2464-905163 -------------------------------------------------------------------- Key fingerprint = DA10 CC82 62F8 1DBB 39A1 1EDC 725B 3317 A8D7 C3A6 Keyserver: http://www.keyserver.net/en/
Joachim Schmitz writes:
I have a python-script getArtikel, which return items from a ZPatterns-Rack, like so:
item=context.getItem("theItemId") return item
this works fine, now I want to override some of the attributes of the item:
item=context.getItem("theItemId") setattr(item.text,item.text_english) # the attribute text_english exists return item
but that results in an error: attributeless object assign or del. I would expect a TypeError, as "setattr" has three parameters: object, attribute name and value. Try:
setattr(item,'text',item.text_english) Dieter
participants (2)
-
Dieter Maurer -
Joachim Schmitz