Character string to ascii value conversion

Emile van Sebille emile at fenx.com
Thu Mar 9 18:35:20 EST 2000


I spent a few minutes looking for a function to convert
a binary string into a number for a project I'm working
on.  I didn't spot anything, so I wrote this:

def asc(strval):
 if len(strval) == 0:
  return 0
 elif len(strval) == 1:
  return long(ord(strval))
 else:
  return 256*(asc(strval[:-1]))+ord(strval[-1])

It basically emulates ord() for longer character strings.

My question is where is this in the standard library?

If-it-is-ly y'rs,

Emile van Sebille
emile at fenx.com
-------------------








More information about the Python-list mailing list