Python Forum

Full Version: Question about sending escape characters by using sendall function (python2.7).
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,

I intend to send function strings to my device, and use python 2.7 socket programming and sendall() function, at the end of the command '\r\n' escape characters should be added according to the protocal and I try to write the command in the following lines:

send_str='function_strings'
con.sendall(send_str+'\r\n')

or write the command like this:

con.sendall(send_str+r'\r\n')

however, I did not receive any respond from my device and have no idea how to correctely send the escape characters in sendall function. I have also attached my short code in the attachment.

Thank you very much in advance.
It is very simple. The string '\r\n' contains two characters: a carriage return and a line feed. The string r'\r\n' contains four characters: a backslash, the letter r, another backslash, the letter n. You need to know what the server is expecting but this is independent from Python programming.