regex/lambda black magic

Max Erickson maxerickson at gmail.com
Thu May 25 13:06:04 EDT 2006


Andrew Robert <andrew.arobert at gmail.com> 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,b16decode 

and use them directly, or 

ret_hex=base64.b16encode

ret_ascii=base64.b16decode

if you want different names.


As far as the rest of your problem goes, I only see one pass being 
made, is the code you posted the code you are running?

Also, is there some reason that base64.b16encode should be returning a 
string that starts with a '%'? 

All I would expect is:

base64.b16decode(base64.b16encode(input))==input

other than that I have no idea about the expected behavior.

max




More information about the Python-list mailing list