how to turn arbitrary binary string into unix filename?

Bill Janssen janssen at parc.xerox.com
Fri Feb 18 15:22:32 EST 2000


I'm sort of surprised that there doesn't seem to be any standard way
to take a binary string in Python and turn it into a text string
suitable for a UNIX filename.  This is handy if you are trying to map
data to filenames, for instance; you take the MD5 hash of the data,
for instance the Message-ID of a mail message, convert it to an ASCII
string (typically by hexifying it), and use that as the filename.  But
after half an hour of poking around, I can't see a standard method
that one can call to hexify a string.

Base64 would almost work, except that it uses '+' and '/' as the
extender characters, and that '/' ruins it for filenames.  ILU uses a
version of base64 that uses '+' and '-' as the extender characters,
for this very reason.

Am I missing something?

Bill




More information about the Python-list mailing list