sendLine 不会发送整数(Twisted Python)

发布于 2024-12-05 16:43:23 字数 1546 浏览 0 评论 0原文

我正在使用 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)

I'm writing a MUD in Python using the Twisted library. I'm currently trying to send a integer through the sendLine method via to the LineReceiver module. However, whenever I try sending a integer I get the below error message while running my program:

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'

The line which is causing the error is:

self.sendLine(SomeVarWhichIsANumber)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玩物 2024-12-12 16:43:23

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

self.sendLine(str(SomeVarWhichIsANumber))

so... send a string:

self.sendLine(str(SomeVarWhichIsANumber))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文