String to ASCII values

B

Benjamin Hepp

Hello,

How do I convert a string like 'A' to its ASCII value(s) ?

Greets,
Benjamin
 
M

Max M

Benjamin said:
Hello,

How do I convert a string like 'A' to its ASCII value(s) ?

The struct module is nifty, and most likely faster than ord()


#########

from struct import unpack

def toBytes(value):
"Turns a string into a list of byte values"
return unpack('%sB' % len(value), value)

print toBytes('ABCDEFG')



regards Max M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,166
Messages
2,570,903
Members
47,444
Latest member
Michaeltoyler01

Latest Threads

Top