Zope/DTML Infuriating...

J

Jens

Hello Everyone.

I am relatively new to Zope(using it for a work project) and I was
wondering if someone here could help me out or at least refer me to a
decent documentationg for Zope/DTML/Python (at the detail level of
php.net or Java API reference). http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition/
isn't really detailed enough for my taste. if it doesn't contain a
exhautive description of all available base classes it's simply no
good as a reference resource.

Anyway I have the following problem. I'm using zope 2.9 and I would
expect the following dtml code to yield a list containing main1, main2
etc.

<dtml-let prefix="'main'">
<ul>
<dtml-in expr="_.range(1,10)">
<li><dtml-var expr="_['prefix'] + _['sequence-item']"></li>
</dtml-in>
</ul>
</dtml-let>

But it doesn't work(and yes i know that i could simply do "... <dtml-
var prefix><dtml-var sequence-item>...", but that's not what i need).
I've the checked that i'm referring to the variables correctly, so the
only explanation i can come up with, is that '+' doesn't result in a
string concatenation (with implicit typecast to string of the integer
variable(this is a interpreted language after all)). It apparently
works in other cases but for some reason not here. I get the following
cryptical error message which makes me none the wiser.

An error was encountered while publishing this resource.

Error Type: AttributeError
Error Value: 'NoneType' object has no attribute 'group'

I would appreciate any feedback you might have regarding this. Thanks
in Advance.
 
M

Marco Mariani

Jens said:
I've the checked that i'm referring to the variables correctly, so the
only explanation i can come up with, is that '+' doesn't result in a
string concatenation (with implicit typecast to string of the integer
variable(this is a interpreted language after all)).

No, sorry. You really need to read the python tutorial at the very least.
You might have wrong assumptions from previous PHP experiences.
Traceback (most recent call last):
 
J

Jens

No, sorry. You really need to read the python tutorial at the very least.
You might have wrong assumptions from previous PHP experiences.

 >>> 'x'+4
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects
 >
... and the non snobby answer would have been:

... <dtml-var expr="_['prefix'] + str(_['sequence-item'])">
 
J

Jens

No, sorry. You really need to read the python tutorial at the very least.
You might have wrong assumptions from previous PHP experiences.

 >>> 'x'+4
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects
 >
... and the non snobby answer would have been:

... <dtml-var expr="_['prefix'] + str(_['sequence-item'])">
 
M

Marco Mariani

Jens said:
You might have wrong assumptions from previous PHP experiences.

Traceback (most recent call last):
... and the non snobby answer would have been:

... <dtml-var expr="_['prefix'] + str(_['sequence-item'])">


Sorry. Not trying to be snobbish, only in a hurry.

That answer would have been less useful, because there are TONS of
details in the python tutorial, that set the language apart from its
"scripting cousins".
Reading the syntax and thinking "yeah, got it, boring, next chapter" is
a common mistake I've also made sometime, especially with python when
I've been deceived by its apparent simplicity.
Then, later, the same happened with Javascript, of course.
And it's bound to happen again, as much as I'll try to be careful :-(
 
J

Jens

... and the non snobby answer would have been:
...  <dtml-var expr="_['prefix'] + str(_['sequence-item'])">

Sorry. Not trying to be snobbish, only in a hurry.

That answer would have been less useful, because there are TONS of
details in the python tutorial, that set the language apart from its
"scripting cousins".
Reading the syntax and thinking "yeah, got it, boring, next chapter" is
a common mistake I've also made sometime, especially with python when
I've been deceived by its apparent simplicity.
Then, later, the same happened with Javascript, of course.
And it's bound to happen again, as much as I'll try to be careful :-(

Hey no worriest. Is this the tutorial you're referring to:

http://docs.python.org/lib/typesmapping.html

Is there anything better? I miss the discussion and examples that
accompany
most entries in php.net.
 
C

Christian Heimes

Jens said:
Hello Everyone.

I am relatively new to Zope(using it for a work project) and I was
wondering if someone here could help me out or at least refer me to a
decent documentationg for Zope/DTML/Python (at the detail level of
php.net or Java API reference). http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition/
isn't really detailed enough for my taste. if it doesn't contain a
exhautive description of all available base classes it's simply no
good as a reference resource.

Are you forced to use DTML for the job? ZPT are far superior and easier
to work with, if you have to output HTML.

Christian
 
J

Jens

... and the non snobby answer would have been:
...  <dtml-var expr="_['prefix'] + str(_['sequence-item'])">

Sorry. Not trying to be snobbish, only in a hurry.

That answer would have been less useful, because there are TONS of
details in the python tutorial, that set the language apart from its
"scripting cousins".
Reading the syntax and thinking "yeah, got it, boring, next chapter" is
a common mistake I've also made sometime, especially with python when
I've been deceived by its apparent simplicity.
Then, later, the same happened with Javascript, of course.
And it's bound to happen again, as much as I'll try to be careful :-(

Hey no worriest. Is this the tutorial you're referring to:

http://docs.python.org/lib/typesmapping.html

Is there anything better? I miss the discussion and examples that
accompany
most entries in php.net.
 
J

Jens

... and the non snobby answer would have been:
...  <dtml-var expr="_['prefix'] + str(_['sequence-item'])">

Sorry. Not trying to be snobbish, only in a hurry.

That answer would have been less useful, because there are TONS of
details in the python tutorial, that set the language apart from its
"scripting cousins".
Reading the syntax and thinking "yeah, got it, boring, next chapter" is
a common mistake I've also made sometime, especially with python when
I've been deceived by its apparent simplicity.
Then, later, the same happened with Javascript, of course.
And it's bound to happen again, as much as I'll try to be careful :-(

Hey no worriest. Is this the tutorial you're referring to:

http://docs.python.org/lib/typesmapping.html

Is there anything better? I miss the discussion and examples that
accompany
most entries in php.net.
 
M

Marco Mariani

Jens said:
Hey no worriest. Is this the tutorial you're referring to:

http://docs.python.org/lib/typesmapping.html

Is there anything better?

That's the library reference - the one to keep under the pillow.
It also documents the core -- i.e. builtin objects.


As for the language semantics, I suggest the whole of

http://docs.python.org/tut/

then a bit of

http://docs.python.org/ref/ref.html

A good alternative could be the new edition of Python in a Nutshell.
The author has a very clear style and leaves no corners uncovered.

I miss the discussion and examples that accompany most entries in php.net.

This is a post + comments about strong/weak typing, although not an
in-depth analyses.

http://www.artima.com/forums/flat.jsp?forum=106&thread=7590
 
W

William Heymann

Hello Everyone.
<dtml-let prefix="'main'">
<ul>
<dtml-in expr="_.range(1,10)">
<li><dtml-var expr="_['prefix'] + _['sequence-item']"></li>
</dtml-in>
</ul>
</dtml-let>


I think you are going to really regret doing things this way, it is only going
to make your life much harder regardless of if you are using zpt or dtml by
doing stuff like this inside the template. The most correct way in zope to do
this is to use a python script object and have the dtml call that.

For example your python script would have

return ['main%s' % i for i in range(1,10)]

and your dtml would have

<ul>
<dtml-in path.to.you.script()>
<li><dtml-var sequence-item></li>
</ul>


This leads to much cleaner and easier to maintain systems.
 
J

Jens

Are you forced to use DTML for the job? ZPT are far superior and easier
to work with, if you have to output HTML.

Christian

For now, I have to use DTML as I am building on an existing solution.
I might look into ZPT's but I have limited time and theres no to time
at this point to redo everything as ZPT. In the long run we're
probably
going in a completely different direction, but that a another story.

I like some aspects of zope but I find that it ends up sitting between
two chairs. On one hand it want's to be a templating language which is
easy to get into for novices, but on the other hand you really have be
familiar with python to be able to so stuff thats only slighty more
complicated
then standard SSI. And don't get me started on the whole security
philosophy.

@Marco:
Thanks for the links :) Python may be one of those really elegant
languages, but the reference is really sub standard. Checkout the
layout
of php.net for comparison. Think what you will about php, but the
reference
is excellent. For that matter check out msdn section on old-school
asp, or
even the common-lisp documentation(http://www.lispworks.com/
documentation/HyperSpec/Front/Contents.htm)
It's accessibility like that i'm missing. It shouldn't take 10 min
and a usenet
post to figure to how to basic stuff like string concatenation. And
theres
still plenty of unanswered questions after checking the reference:

- What is the exact definition of the operator e.g. op + (<string>,
<string>) -> <string>, op + (<int>, <int>) : <int>, op + (<float> ...
- What is the exact operator precedence
- Why is it, when primitive data types seem to be objects (similar to
javascript), that type casting is done through build-in functions
rather than methods, e.g. String.toInt('5') or '5'.toInt() or x =
Integer.fromString('5').
 
J

Jens

Are you forced to use DTML for the job? ZPT are far superior and easier
to work with, if you have to output HTML.

Christian

For now, I have to use DTML as I am building on an existing solution.
I might look into ZPT's but I have limited time and theres no to time
at this point to redo everything as ZPT. In the long run we're
probably
going in a completely different direction, but that a another story.

I like some aspects of zope but I find that it ends up sitting between
two chairs. On one hand it want's to be a templating language which is
easy to get into for novices, but on the other hand you really have be
familiar with python to be able to so stuff thats only slighty more
complicated
then standard SSI. And don't get me started on the whole security
philosophy.

@Marco:
Thanks for the links :) Python may be one of those really elegant
languages, but the reference is really sub standard. Checkout the
layout
of php.net for comparison. Think what you will about php, but the
reference
is excellent. For that matter check out msdn section on old-school
asp, or
even the common-lisp documentation(http://www.lispworks.com/
documentation/HyperSpec/Front/Contents.htm)
It's accessibility like that i'm missing. It shouldn't take 10 min
and a usenet
post to figure to how to basic stuff like string concatenation. And
theres
still plenty of unanswered questions after checking the reference:

- What is the exact definition of the operator e.g. op + (<string>,
<string>) -> <string>, op + (<int>, <int>) : <int>, op + (<float> ...
- What is the exact operator precedence
- Why is it, when primitive data types seem to be objects (similar to
javascript), that type casting is done through build-in functions
rather than methods, e.g. String.toInt('5') or '5'.toInt() or x =
Integer.fromString('5').
 
A

Arnaud Delobelle

Jens said:
@Marco: Thanks for the links :) Python may be one of those really
elegant languages, but the reference is really sub
standard. Checkout the layout of php.net for comparison. Think what
you will about php, but the reference is excellent. For that matter
check out msdn section on old-school asp, or even the common-lisp
documentation(http://www.lispworks.com/
documentation/HyperSpec/Front/Contents.htm)

Beauty is in the eye of the beholder. I'm used to the python doc
layout, and I can find my way round it pretty fast. What I like about
it is that it is organised thematically, so it is usually possible to
think your way to where the relevant documentation is. Moreover,
Python has a very useful help functionality:

* at the interactive prompt:

Will give you lots of useful information

* At the shell prompt:

It's accessibility like that i'm missing. It shouldn't take 10 min
and a usenet post to figure to how to basic stuff like string
concatenation.

It takes time to learn a language, and that includes learning how the
documentation is organised.
And theres still plenty of unanswered questions after checking the
reference:

- What is the exact definition of the operator e.g. op + (<string>,
<string>) -> <string>, op + (<int>, <int>) : <int>, op + (<float> ...

The answers are here (in the library reference you checked):
http://docs.python.org/lib/types.html
- What is the exact operator precedence

That's a language feature, so it's in the *language* reference.
http://docs.python.org/ref/summary.html
- Why is it, when primitive data types seem to be objects (similar to
javascript), that type casting is done through build-in functions
rather than methods, e.g. String.toInt('5') or '5'.toInt() or x =
Integer.fromString('5').

Because Python is not Javascript?

In fact some are methods, e.g. str(x) is shorthand for x.__str__().
 
M

Michael Torrie

Jens said:
- Why is it, when primitive data types seem to be objects (similar to
javascript), that type casting is done through build-in functions
rather than methods, e.g. String.toInt('5') or '5'.toInt() or x =
Integer.fromString('5').

Mainly because it's much cleaner to do it the python way (absolutely
explicit), and just as clear or clearer what you are intending to do.
Digging a little deeper, you'll find that the built-in function "str,"
for example, actually calls object.__str__(). This is nice because it
allows any object class to define that method and have it work with
str() in a manner consistent across python. It preserves some amount of
uniformity.

The second example, x = Integer.fromString('5') demonstrates a huge
weakness in Java. In python, rather than asking an integer object to
convert from a limited selection of other objects, python works the
other way, asking objects to convert themselves to integers (if they
can). We don't worry about the size of integers, since python's
integers are auto-sizing. So any object that implements the __int__()
method can be used with the classic "int()" built-in function. The same
goes for __float__ and float().

Little things like this really make me happy about how python does
things generally. I think much of how Java works with Integer and
String (as you describe above) is because Java has primitive types
(which aren't objects at all) and then boxed objects around the
primitive types. Python eliminates this idea, and makes everything,
even "simple" types objects.

Now sure python could just say always call the "int()" or "float()" or
"str()" method on objects to produce those respective conversions. But
using a combination of a built-in language function and a specialized,
reserved class method name, allows a lot of flexibility without
infringing on the programmer's need to use method names like "int,
float, or str" if he or she so desired.
 
M

Michael L Torrie

Michael said:
The second example, x = Integer.fromString('5') demonstrates a huge
weakness in Java.

Ahem. Javascript. Sorry.

--
Michael Torrie
Assistant CSR, System Administrator
Chemistry and Biochemistry Department
Brigham Young University
Provo, UT 84602
+1.801.422.5771

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top