> De : [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] De la part de
> Tudor Gabriel
> Envoyé : mercredi 13 juin 2007 01:54
> À : firstname.lastname@example.org
> Objet : [Zope] basic python class & zope question
> hi im new here , first post ... and new to zope.
> i've read the manual ... and zope framework looks very promising ...
> i started writing a couple of templates ... and run into some basic
> problems like:
> Problem 1.
> is it posible to have a python class ... defined in a script .... like
> class learn:
> def print_something(self):
> print 'it works'
> and call it from zpt ... like <span
> or how can i call a method from this object ? ... i tryied with
> python:learn.print_something() and many different ways and i still
> don't get it.
> i'm starting to suspect that i can use classes only as zope products ....
> and call from zpt ... only scripts without classes.
> also do i have to set the properties/attributes of the script which
> contains the class ... with the methods?
> because by calling learn/print_somthing i get an AttributeError ... url
> might be invalid etc...
> Problem 2.
> how can i call/return from an python script a html file which resides in
> some folder above the script.
> i wanna call abc/index.html ... from abc/def/script.py
> i tryied with the container[' index.html'[ but it doesn't return anything.
> thank you for the patience and sorry for the very basic questions ... but
> i feel that if i understand this things ... i can really get started with
> or how can i call a method from this object ?
To call a method of a class, you first have to possess an instance of that
class in a variable. Then, supporing the variable is lrn_instance, you can use
lrn_instance/print_something or python:lrn_instance.print_something() to call
> is it posible to have a python class ... defined in a script
> because by calling learn/print_somthing i get an AttributeError
It should be possible to define a class in a script, but the script won't
become that class, you will have to have that script return an instance of the
class, and then you store it somewhere (a variable maybe, or a property of some
other object if you want it to persist). As far as I can tell, it would
probably be wiser to define the class in a Product, though.
> how can i call/return from an python script a html file which resides...
This behaviour is built into Zope and is called acquisition: anything defined
above your context is accessible as if it were in your context, as long as it
isn't obscured by something else with the same name.
The things you want to access will lose their extension, by the way:
index_html.pt will become index_html, the same way that script.py becomes script
>From abc/def/script.py, "context.index_html()" should give you the rendering
Hope this helps,
This message contains information that may be privileged or confidential and is
the property of the Capgemini Group. It is intended only for the person to whom
it is addressed. If you are not the intended recipient, you are not authorized
to read, print, retain, copy, disseminate, distribute, or use this message or
any part thereof. If you receive this message in error, please notify the
sender immediately and delete all copies of this message.
Zope maillist - Zope@zope.org
** No cross posts or HTML encoding! **
(Related lists -