regex/lambda black magic

Max Erickson maxerickson at
Thu May 25 17:13:54 CEST 2006

Andrew Robert <andrew.arobert at> wrote:

> ValueError: invalid literal for int(): %
> Does anyone see what I am doing wrong?

Try getting rid of the lamba, it might make things clearer and it 
simplifies debugging. Something like(this is just a sketch):

def callback(match):
    return chr(int(,16)) % ord(

output.write(re.sub('r([^\w\s])', callback, line)

It looks like your is a '%' character:

>>> int('%', 16)
Traceback (most recent call last):
  File "<pyshell#108>", line 1, in ?
    int('%', 16)
ValueError: invalid literal for int(): %


More information about the Python-list mailing list