Serhiy Storchaka wrote: > On 07.02.13 11:49, Peter Otten wrote: >> ILLEGAL = "-:./?&=" >> try: >> TRANS = string.maketrans(ILLEGAL, "_" * len(ILLEGAL)) >> except AttributeError: >> # python 3 >> TRANS = dict.fromkeys(map(ord, ILLEGAL), "_") > > str.maketrans()
D'oh.
ILLEGAL = "-:./?&="
try:
maketrans = str.maketrans
except AttributeError:
# python 2
from string import maketrans
TRANS = maketrans(ILLEGAL, "_" * len(ILLEGAL))
...
--
http://mail.python.org/mailman/listinfo/python-list
