Is there a way to make python2 scripts compatible with python3 with telnetlib?
I noticed that I need to prefix read_until() with the letter b, and I need to use encode('ascii') on the string when I want to write().
Python2
tn = telnetlib.Telnet("192.168.1.45")
tn.write("ls " + dirname + "\n")
answer = tn.read_until(":/$")
Python3
tn = telnetlib.Telnet("192.168.1.45")
cmd_str = "ls " + dirname + "\n"
tn.write(cmd_str.encode('ascii'))
answer = tn.read_until(b":/$")
This would help me update many scripts to 3.x as it the only major change.
Thanks!