Jes*_*ren 4 python unicode utf-8
代码:
class EchoClient(protocol.Protocol):
def connectionMade(self):
self.transport.write("Hello World!")
Run Code Online (Sandbox Code Playgroud)
错误:
##raise TypeError("Data must not be unicode") builtins.TypeError: Data must not be unicode ##
我如何将代码编写为 utf-8?
假设您使用的是 Python3,请尝试:
"Hello World!".encode('utf-8')
Run Code Online (Sandbox Code Playgroud)
如果您的数据在str变量中,请尝试:
# s = "Hello World!"
s.encode('utf-8')
Run Code Online (Sandbox Code Playgroud)