how to turn arbitrary binary string into unix filename?
sdyer7073 at my-deja.com
Wed Feb 23 01:21:15 CET 2000
Here is another possible solution for that problem that I have used (it
takes advantage of the fact that a string is also a sequence type):
>>> import md5, string
>>> md.update('Test Message')
>>> string.join(map(lambda x: '%02x' % ord(x), md.digest()),'')
In article <Pine.BSF.4.10.10002181615490.11934-100000 at chi.pair.com>,
"Michal Wallace (sabren)" <sabren at manifestation.com> wrote:
> On Fri, 18 Feb 2000, Bill Janssen wrote:
> > 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
> > 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
> > string (typically by hexifying it), and use that as the filename.
> > after half an hour of poking around, I can't see a standard method
> > that one can call to hexify a string.
> Hey Bill,
> This code takes a binary string and converts it to a
> hexidecimal representation. (It doubles the length
> but only uses the characters 0-9 and a-f)
> def hexify(binaryString):
> result = ""
> for i in binaryString:
> result = result + string.zfill(hex(ord(i))[2:],2)
> return result
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list