Skip to content Skip to sidebar Skip to footer

How Can I Send Anything Other Than Strings Through Python Sock.send()

I'm very very new to programming in Python, but out of necessity I had to hack something together very quick. I am trying to send some data over UDP, and I have everything working

Solution 1:

Are you using Python 2.7 or 3.2?

In 3.2 you could do:

data = bytes.fromhex('01AF23')
s.send(data)

Data would then be equal to:

b'\x01\xAF\x23'

In 2.7 the same could be accomplished with:

data = '01AF23'.decode('hex')

Post a Comment for "How Can I Send Anything Other Than Strings Through Python Sock.send()"