sendLine赢得';t发送整数(Twisted Python)
我正在使用Twisted库用Python编写一个MUD。我目前正试图通过sendLine方法将整数发送到LineReceiver模块。但是,每当我尝试发送整数时,在运行程序时会收到以下错误消息:sendLine赢得';t发送整数(Twisted Python),python,network-programming,twisted,mud,Python,Network Programming,Twisted,Mud,我正在使用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 callWit
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(str(SomeVarWhichIsANumber))
我试过了,但没用。然而,在你建议这样做之后,我又尝试了第二次,由于一些奇怪的原因,它可以工作。当然它不发送整数。它发送。。。线。。。
self.sendLine(str(SomeVarWhichIsANumber))