开发者

sendLine Won't Send integers (Twisted Python)

开发者 https://www.devze.com 2023-04-06 07:41 出处:网络
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

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-pack开发者_运维百科ages\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)


so... send a string:

self.sendLine(str(SomeVarWhichIsANumber))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号