python 报错
TypeError: 'in ’ requires string as left operand, not int
原因:类型没对齐
username = ‘root’
tn.write(username + str(’\n’))
就会报错
应该改成
tn.write(username.encode(‘ascii’) + str(’\n’))
python3 中 文本字符串类型(unicode编码)被命名为str,字节字符串类型被命名为bytes,其中 str encode 得到 bytes, bytes decode 得到 str
本文解决了一个常见的Python编程问题,即当尝试将不同类型的变量(如字符串和整数)进行拼接时引发的TypeError。通过正确的类型转换,可以避免这类错误并确保程序正常运行。
1984

被折叠的 条评论
为什么被折叠?



