Skip to content
Advertisement

Which is the character in python?

Im communicating with physical equipments via python socket. Im kinda used to doing it, but not an expert. The commands which i send to the equipments are usually found in the equipment’s manuals. Usually, commands end with CR or LF (or both) and work well when i do something like:

mysocket.send((command+”rn”).encode())

With “rn” acting as CRLF (although as this answer says, CRLF and rn are not exactely the same thing)

I found an equipment which needs to end commands with ENQUIRY char which, according to the manual, has hexadecimal code equal to 05 in the ASCII table (the manual also says the hexadecimal code of CR and LF which are 0D and 0A, so i think its correct).

Although i have looked into the ASCII table, it has no char related to this or even CR and LF. Is there a different table for chars used with these meanings in different languages? What should i put inside an encoded string to match the meaning in python?

Advertisement

Answer

You can use

chr(charCode)

to retrieve the correct character for any given ASCII number.

https://docs.python.org/3/library/functions.html#chr

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement