[Tutor] Question on regular expressions
Andrew Robert
andrew.arobert at gmail.com
Thu May 25 15:37:47 CEST 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi all,
I tried:
output = open(r'e:\pycode\new_test.txt','wb')
for line in open(r'e:\pycode\out_test.txt','rb') :
output.write( re.sub(r'([^\w\s])', lambda s: chr(int(s.group(),
16))) % ord(s.group()), line))
This generated the traceback:
File "E:\pycode\sample_decode_file_specials_from_hex.py", line 8
output.write( re.sub(r'([^\w\s])', lambda s: chr(int(s.group(),
16))) % ord(s.group()), line))
^
SyntaxError: invalid syntax
By any chance, do you see where the syntax issue is?
Kent Johnson wrote:
> Andrew Robert wrote:
<snip>
</snip>
> Use int(s, 16) to convert a base 16 string to an integer, and chr() to
> convert the int to a string. So something like this:
> lambda s: chr(int(s.group(), 16)))
>
> Kent
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
- --
Thank you,
Andrew Robert
Systems Architect
Information Technologies
MFS Investment Management
Phone: 617-954-5882
E-mail: arobert at mfs.com
Linux User Number: #201204
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)
iD8DBQFEdbMrDvn/4H0LjDwRAi09AKC1I6XIcXiqYmpk4hpcbnkwux1NawCgt/zp
xySHXPrh5JncZphAcVRtbtI=
=xtr9
-----END PGP SIGNATURE-----
More information about the Tutor
mailing list