[ZPT] Getting at string module from a PT

Wade Leftwich wade@lightlink.com
Sat, 9 Jun 2001 09:42:31 -0400


Is there a way to import a Python module into a template?

Right now, to use for example string.upper(), I make a script,
lib/string/upper:

def my_upper(s):
  import string
  if same_type(s, ''):
    return string.upper(s)
  else:
    return s

return my_upper

. . . which I can then grab by saying:
<span tal:define="global upper container/lib/string/upper"/>
<p tal:content="python:upper('foo')"/>

My question is: Is there a [ better | more direct | more Pythonic ] way of
using string.upper() in a PT?


-- Wade Leftwich
   Ithaca, NY