Re: Zope/DTML Infuriating...

2008-05-01 Thread Michael Torrie
Jens wrote:
 - 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.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Zope/DTML Infuriating...

2008-05-01 Thread Michael Torrie
Michael Torrie wrote:
 The second example, x = Integer.fromString('5') demonstrates a huge
 weakness in Java.  

Ahem.  Javascript.  Sorry.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Zope/DTML Infuriating...

2008-05-01 Thread Michael L Torrie
Michael Torrie wrote:
 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?

--
http://mail.python.org/mailman/listinfo/python-list


Zope/DTML Infuriating...

2008-04-29 Thread 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)
  lidtml-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 prefixdtml-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.


--
http://mail.python.org/mailman/listinfo/python-list


Re: Zope/DTML Infuriating...

2008-04-29 Thread Marco Mariani

Jens wrote:


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.

 'x'+4
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: cannot concatenate 'str' and 'int' objects


--
http://mail.python.org/mailman/listinfo/python-list


Re: Zope/DTML Infuriating...

2008-04-29 Thread Jens
On Apr 29, 1:59 pm, Marco Mariani [EMAIL PROTECTED] wrote:
 Jens wrote:
  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.

   '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'])
--
http://mail.python.org/mailman/listinfo/python-list


Re: Zope/DTML Infuriating...

2008-04-29 Thread Jens
On Apr 29, 1:59 pm, Marco Mariani [EMAIL PROTECTED] wrote:
 Jens wrote:
  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.

   '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'])
--
http://mail.python.org/mailman/listinfo/python-list


Re: Zope/DTML Infuriating...

2008-04-29 Thread Marco Mariani

Jens wrote:


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'])



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 :-(
--
http://mail.python.org/mailman/listinfo/python-list


Re: Zope/DTML Infuriating...

2008-04-29 Thread Jens
On Apr 29, 2:45 pm, Marco Mariani [EMAIL PROTECTED] wrote:
 Jens wrote:
  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'])

 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.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Zope/DTML Infuriating...

2008-04-29 Thread Jens
On Apr 29, 2:45 pm, Marco Mariani [EMAIL PROTECTED] wrote:
 Jens wrote:
  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'])

 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.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Zope/DTML Infuriating...

2008-04-29 Thread Jens
On Apr 29, 2:45 pm, Marco Mariani [EMAIL PROTECTED] wrote:
 Jens wrote:
  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'])

 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.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Zope/DTML Infuriating...

2008-04-29 Thread Marco Mariani

Jens wrote:


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=106thread=7590

--
http://mail.python.org/mailman/listinfo/python-list


Re: Zope/DTML Infuriating...

2008-04-29 Thread Christian Heimes
Jens schrieb:
 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

--
http://mail.python.org/mailman/listinfo/python-list


Re: Zope/DTML Infuriating...

2008-04-29 Thread William Heymann
On Tuesday 29 April 2008, Jens wrote:
 Hello Everyone.


 dtml-let prefix='main'
 ul
 dtml-in expr=_.range(1,10)
   lidtml-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()
 lidtml-var sequence-item/li
/ul


This leads to much cleaner and easier to maintain systems.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Zope/DTML Infuriating...

2008-04-29 Thread Jens
On Apr 29, 3:16 pm, Christian Heimes [EMAIL PROTECTED] wrote:
 Jens schrieb:

  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

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').



--
http://mail.python.org/mailman/listinfo/python-list


Re: Zope/DTML Infuriating...

2008-04-29 Thread Jens
On Apr 29, 3:16 pm, Christian Heimes [EMAIL PROTECTED] wrote:
 Jens schrieb:

  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

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').



--
http://mail.python.org/mailman/listinfo/python-list


Re: Zope/DTML Infuriating...

2008-04-29 Thread Arnaud Delobelle
Jens [EMAIL PROTECTED] writes:
[...]
 @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:

 help(someobject)
 help(somemodule)

Will give you lots of useful information

* At the shell prompt:

$ pydoc keyword
-- documentation about keyword

 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__().

-- 
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list