【问题标题】:Bad operand type for unary str in python networkingpython网络中一元str的错误操作数类型
【发布时间】:2017-11-21 01:38:00
【问题描述】:

我正在学习绑定和监听套接字,所以当我写完代码通过 cmd 连接到给定的本地主机时,它得到了以下错误。

s.listen(5)

conn, addr = s.accept()

print('connected with: ', + addr[0] + ':' + str(addr[1]))

我收到以下错误:

Traceback (most recent call last):

  File "C:/Users/vineel/Desktop/Python34/PYTHON NETWORKING/bindsockets.py", line 19, in <module>

   print('connected with: ', + addr[0] + ':' + str(addr[1]))

TypeError: bad operand type for unary +: 'str'

【问题讨论】:

    标签: python sockets cmd telnet


    【解决方案1】:
    print('connected with: ', + addr[0] + ':' + str(addr[1]))
    

    应该是(没有逗号):

    print('connected with: ' + addr[0] + ':' + str(addr[1]))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-02
      • 1970-01-01
      • 1970-01-01
      • 2013-03-28
      • 1970-01-01
      • 2021-01-15
      • 1970-01-01
      相关资源
      最近更新 更多