From: The Doctor What <docwhat@gerf.org>
For those of us who are trying to figure out everything at a low level, where would this be in the source?
Here's an example of adding stuff to '_' using a monkey patch Product. Contents of __init__.py of directory Products/MoreBuiltins: def _AddBuiltins(): from urllib import urlopen, quote, unquote from base64 import decodestring, encodestring def same_type(self, a, b): return type(a)==type(b) def attr_map(self, o): r = o.__dict__.copy() for k in r.keys(): if k[:1] == '_': del r[k] return r class AnObject: def __init__(self, **kw): self.__dict__.update(kw) NewBuiltins = { 'list': list, 'tuple': tuple, 'map': map, 'filter': filter, 'reduce': reduce, 'urllib': AnObject(open=urlopen, quote=quote, unquote=unquote), 'base64': AnObject(decode=decodestring, encode=encodestring), 'same_type': same_type, 'attr_map': attr_map, } from DocumentTemplate.DT_Util import TemplateDict TemplateDict.__dict__.update(NewBuiltins) #call it _AddBuiltins()