regex/lambda black magic
Max Erickson
maxerickson at gmail.com
Thu May 25 11:13:54 EDT 2006
Andrew Robert <andrew.arobert at gmail.com> 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):
print match.group()
return chr(int(match.group(),16)) % ord(match.group())
output.write(re.sub('r([^\w\s])', callback, line)
It looks like your match.group is a '%' character:
>>> int('%', 16)
Traceback (most recent call last):
File "<pyshell#108>", line 1, in ?
int('%', 16)
ValueError: invalid literal for int(): %
>>>
max
More information about the Python-list
mailing list