[Zope] Typecasting in DTML (or is this Python?)
Dylan Reinhardt
zope@dylanreinhardt.com
18 Jul 2003 08:02:44 -0700
On Fri, 2003-07-18 at 02:17, Julian Clark wrote:
> I'm only familiar with typecasting from my experience in Java
Ah, right. To me, typecasting is something you deal with in C.
Anyway...
> it doesn't look like you're using the % as modulus in this context.
You're right about that.
x % y
can mean two things, depending on what x and y are.
If x and y are numeric types, it means "x mod y."
If, however, x is a string containing special sequences like %s or %d
and y is a variable or tuple that has the same number of elements, the
expression returns y formatted in the way x specifies.
Two quick examples:
'%s' % x # x formatted as a string
'%s %s' % (x, y) # x and y as a string with a space.
There are other fun things you can do with this operator... it's worth
reading up on.
If you're just getting started with Python, you're in luck... there are
a number of great tutorials available. See this page for links to a
bunch of them:
http://python.org/doc/Intros.html
HTH,
Dylan