Convert variable directly into a string (no ASCII)

  • Thread starter Justin Rajewski
  • Start date
J

Justin Rajewski

Hello,

I need to print variables out over serial, however I need them to not be
in ASCII, ie if the variable is 5 then print 5 not "5".

The function that writes to the serial port requires a string and I can
send non-variables out with the string "/x05" for 5.

Is this even possible?

Thanks,
Justin
 
G

Günther Dietrich

Justin Rajewski said:
I need to print variables out over serial, however I need them to not be
in ASCII, ie if the variable is 5 then print 5 not "5".

The function that writes to the serial port requires a string and I can
send non-variables out with the string "/x05" for 5.

See module struct:
'\x05\x96\x03\xe0'



Regards,

Günther
 
M

Martin v. Löwis

I need to print variables out over serial, however I need them to not be
in ASCII, ie if the variable is 5 then print 5 not "5".

The function that writes to the serial port requires a string and I can
send non-variables out with the string "/x05" for 5.

Is this even possible?

So you have a number N given, between 0 and 255, and you want to send
the byte whose ordinal is N. Right? Send chr(N).

HTH,
Martin
 
U

Ulrich Eckhardt

Justin said:
I need to print variables out over serial, however I need them to not be
in ASCII, ie if the variable is 5 then print 5 not "5".

The function that writes to the serial port requires a string and I can
send non-variables out with the string "/x05" for 5.

Take a look at the chr() function. For completeness, the complementary one
is ord(). However, also take a look at the 'struct' module, which is the
tool of choice if you want to do other formatting operations.

I seem to remember there was a third tool that can be used for similar
tasks, but I forgot which it was...

Uli
 

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
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top