Andrew Robert wrote:
> -----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?

You have an argument in the wrong place. Stop trying to do everything in 
one line! Put the lambda in a def'd function. Put the re.sub on it's own 
line. You are tripping over unnecessary complexity. I'm not going to fix 
it any more.

Kent

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to