Re: regex/lambda black magic

2006-05-25 Thread John Machin
On 26/05/2006 4:33 AM, Andrew Robert wrote: > Hi Everyone, > > > Thanks for all of your patience on this. > > I finally got it to work. > > > Here is the completed test code showing what is going on. Consider doing what you should have done at the start: state what you are trying to achieve.

Re: regex/lambda black magic

2006-05-25 Thread Andrew Robert
Hi Everyone, Thanks for all of your patience on this. I finally got it to work. Here is the completed test code showing what is going on. Not cleaned up yet but it works for proof-of-concept purposes. #!/usr/bin/python import re,base64 # Evaluate captured character as hex def ret_hex(va

Re: regex/lambda black magic

2006-05-25 Thread Max Erickson
Andrew Robert <[EMAIL PROTECTED]> wrote: > import re,base64 > > # Evaluate captured character as hex > def ret_hex(value): > return base64.b16encode(value) > > def ret_ascii(value): > return base64.b16decode(value) > Note that you can just do this: from base64 import b16encode,b16dec

Re: regex/lambda black magic

2006-05-25 Thread Andrew Robert
Max Erickson wrote: > Try getting rid of the lamba, it might make things clearer and it > simplifies debugging. Something like(this is just a sketch): > > > max > Yeah.. trying to keep everything on one line is becoming something of a problem. To make this easier, I followed something from

Re: regex/lambda black magic

2006-05-25 Thread Max Erickson
Andrew Robert <[EMAIL PROTECTED]> 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.

regex/lambda black magic

2006-05-25 Thread Andrew Robert
Hi everyone, I have two test scripts, an encoder and a decoder. The encoder, listed below, works perfectly. 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)