Learning Python Syntax for Zope Objects and DTML Operations
What is the recommended way to learn how to carry out both API access and DTML equvalence in Python scripts? I find myself frequently spending what seems like an inordinate amount of time trying to translate the way DTML deals with something into a Python equivalent. Th Zope Book basically waves its arms and says to consult the appendices but they don't really tell someone lilke me, who doesn't already have a good idea what's going on, how to do this mapping. Only by way of example, I've been working on learning iterators in DTML and finding the syntax pretty opaque. If I have a collection of DTML Methods in a folder, some of them having a property called "status" and I want to produce a list of *only* those DTML methods that *have* that property and have it set to some value, I get into some gnarly DTML code. So I figure, what the heck,I know how to do iterators in Python in my sleep, I'll write a Python script. But I can't figure out how to reference the objects, let alone iterate over them. I'll probably figure this out myself before too long, but I'm looking for a basic learning experience here. Surely someone somewhere has written some definitive material on how to talk to Zope and ZODB via Python with sufficient detail to be usable?
Dan Shafer writes:
.... If I have a collection of DTML Methods in .... But I can't figure out how to reference the objects, let alone iterate over them. Please read about "Bindings" in the Python Script documentation. This will tell you how to access the objects.
Please look into the Python Language Reference (or an elementary Python book) for "for" to learn about iteration in Python. Your solution will somehow look like: for o in context.objectValues(['DTML Method']): # do something with your object Dieter
Thanks for the response, Dieter. At 10:14 PM 5/5/2002 +0200, Dieter Maurer wrote:
Dan Shafer writes:
.... If I have a collection of DTML Methods in .... But I can't figure out how to reference the objects, let alone iterate over them. Please read about "Bindings" in the Python Script documentation. This will tell you how to access the objects.
This was the missing piece for me. Is there any *specific* Python Script documentation you have in mind? I will go rummaging about and see what I can locate but if you have a specific pointer, that would be helpful and time-saving.
Please look into the Python Language Reference (or an elementary Python book) for "for" to learn about iteration in Python.
I knew I had to use a "for" construct, the problem was creating the rest of the line, as you have done here. Is this syntax *always* consistent? I.e., is it always context.someDTMLfunction(['list of', 'string arguments'])? Thanks again. I'll get this soon, I'm sure!
Your solution will somehow look like:
for o in context.objectValues(['DTML Method']): # do something with your object
Dieter
On Sun, May 05, 2002 at 02:52:27PM -0700, Dan Shafer wrote: | At 10:14 PM 5/5/2002 +0200, Dieter Maurer wrote: | >Please look into the Python Language Reference (or an elementary | >Python book) for "for" to learn about iteration in Python. | | I knew I had to use a "for" construct, the problem was creating the rest of | the line, as you have done here. Is this syntax *always* consistent? Yes. | I.e., | is it always context.someDTMLfunction(['list of', 'string arguments'])? Only if that function call yields the sequence of objects you want to iterate over. If you want to iterate a certain number of times, then your loop will look like for i in range( 10 ) : print i The key to determining what to put between 'in' and ':' is to determine what sequence of objects you want to iterate over. -D -- "Piracy is not a technological issue. It's a behavior issue." --Steve Jobs GnuPG key : http://dman.ddts.net/~dman/public_key.gpg
Dan Shafer writes:
...
Please read about "Bindings" in the Python Script documentation. This will tell you how to access the objects.
This was the missing piece for me. Is there any *specific* Python Script documentation you have in mind? I will go rummaging about and see what I can locate but if you have a specific pointer, that would be helpful and time-saving. What about the Zope Book or
<http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html>
Please look into the Python Language Reference (or an elementary Python book) for "for" to learn about iteration in Python.
I knew I had to use a "for" construct, the problem was creating the rest of the line, as you have done here. Is this syntax *always* consistent? I.e., is it always context.someDTMLfunction(['list of', 'string arguments'])? It is *never* "someDTMLfunction([...])".
You need to split things into different subtasks. Otherwise, you will loose: Again: * you access objects (and their attributes) via the bindings * you interate over sequences with: "for XXXX in SEQUECNE" * you call methods according to their API (see embedded online help -> Zope Help -> API reference) Especially, you do not call DTML objects with a list of strings as single parameter (more in "calling DTML objects" in the above reference. Dieter
participants (3)
-
Dan Shafer -
Dieter Maurer -
dman