Andrew Robert wrote: > Taking this a little further along, I wrote the converted file to a new > file using: > > > import re,sys > > output = open(r'e:\pycode\out_test.txt','wb') > > for line in open(r'e:\pycode\sigh.txt','rb') : > output.write( re.sub(r'([^\w\s])', lambda s: '%%%2X' % > ord(s.group()), line)) > > output.close() > > > Not elegant but its strictly for test :) > > > Last part and we can call it a day. > > How would you modify the lambda statement to covert a the hex value back > to its original value?
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@python.org http://mail.python.org/mailman/listinfo/tutor