【问题标题】:sendLine Won't Send integers (Twisted Python)sendLine 不会发送整数(Twisted Python)
【发布时间】:2011-09-21 19:48:46
【问题描述】:

我正在使用 Twisted 库在 Python 中编写 MUD。我目前正在尝试通过 sendLine 方法将整数发送到 LineReceiver 模块。但是,每当我尝试发送整数时,都会在运行程序时收到以下错误消息:

Unhandled Error
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\twisted\python\log.py", line 84, in
thLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "C:\Python27\lib\site-packages\twisted\python\log.py", line 69, in
thContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "C:\Python27\lib\site-packages\twisted\python\context.py", line 118
allWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "C:\Python27\lib\site-packages\twisted\python\context.py", line 81,
llWithContext
    return func(*args,**kw)
--- <exception caught here> ---
  File "C:\Python27\lib\site-packages\twisted\internet\selectreactor.py",
46, in _doReadOrWrite
    why = getattr(selectable, method)()
  File "C:\Python27\lib\site-packages\twisted\internet\tcp.py", line 460,
ead
    rval = self.protocol.dataReceived(data)
  File "C:\Python27\lib\site-packages\twisted\protocols\basic.py", line 56
dataReceived
    why = self.lineReceived(line)
  File "server.py", line 37, in lineReceived
    self.sendLine(level)
  File "C:\Python27\lib\site-packages\twisted\protocols\basic.py", line 62
sendLine
    return self.transport.write(line + self.delimiter)
exceptions.TypeError: unsupported operand type(s) for +: 'int' and 'str'

导致错误的行是:

self.sendLine(SomeVarWhichIsANumber)

【问题讨论】:

  • 当然它不发送整数。它发送...行...

标签: python network-programming twisted mud


【解决方案1】:

所以...发送一个字符串:

self.sendLine(str(SomeVarWhichIsANumber))

【讨论】:

  • 我试过了,但没用。但是,在您建议这样做之后,我再次尝试了它,但由于某种奇怪的原因它起作用了。
猜你喜欢
  • 2014-07-15
  • 1970-01-01
  • 2017-06-24
  • 1970-01-01
  • 2014-02-20
  • 1970-01-01
  • 2010-11-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多