[Tutor] Question on regular expressions
Andrew Robert
andrew.arobert at gmail.com
Thu May 25 16:08:22 CEST 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
When I alter the code to:
import re,sys
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)))
, line)
output.close()
I get the trace:
Traceback (most recent call last):
File "E:\pycode\sample_decode_file_specials_from_hex.py", line 8, in ?
output.write( re.sub(r'([^\w\s])', lambda s: chr(int(s.group(),
16))) , line)
TypeError: sub() takes at least 3 arguments (2 given)
It appears that the code is not recognizing the line.
I checked the parentheses and they appear to be properly enclosed.
Any ideas?
Kent Johnson wrote:
<snip>
</snip>
> Take out " % ord(s.group())" - the result of chr() is the actual string
> you want, not a format string.
>
> The syntax error is caused by mismatched parentheses.
>
> 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)
iD8DBQFEdbpWDvn/4H0LjDwRAhEmAJ9WSfKitH1VgsTD5kTLI4cWP5YZRwCgs0mz
Y9jl5l6Q/VZe6NmUaibZGa4=
=nezG
-----END PGP SIGNATURE-----
More information about the Tutor
mailing list