Character string to ascii value conversion

Jeff Pinyan jeffp at crusoe.net
Thu Mar 9 20:07:17 EST 2000


[posted & mailed]

On Mar 9, Emile van Sebille said:

>I spent a few minutes looking for a function to convert
>a binary string into a number for a project I'm working
[...]
>My question is where is this in the standard library?

Sounds like you want struct.pack or struct.unpack.

  import struct
  def asc (string):
    # struct.unpack always returns a tuple...
    return (struct.unpack("L",string))[0]

-- 
MIDN 4/C PINYAN, NROTCURPI, US Naval Reserve             japhy at pobox.com
http://www.pobox.com/~japhy/                  http://pinyaj.stu.rpi.edu/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/





More information about the Python-list mailing list