namespaces

deelan ggg at zzz.it
Sun Jul 31 05:58:32 EDT 2005


Paolino wrote:
(...)
> What I'm needing as a global (in globals() or at the module level or in 
> the module namespace) is 'translate'.The rest of bindings (all,badcars 
> and table) is something which is 'polluting' the module namespace.

try this:

## yourmodule.py ##

def _setup_table():
   import string
   all=string.maketrans('','')
   badcars=all.translate(all,string.letters+string.digits)
   return string.maketrans(badcars,'_'*len(badcars))

TABLE = _setup_table()

# optional, get rid of _setup_table symbol
del _setup_table()

def translate(text):
   return text.translate(TABLE)



HTH,
deelan.

-- 
deelan, #1 fan of adriana lima!
<http://www.deelan.com/>



More information about the Python-list mailing list