当我运行我的代码时,我收到此错误:
UserId = "{}".format(source[1]) UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)
我的代码是:
def view_menu(type, source, parameters):
ADMINFILE = 'static/users.txt'
fp = open(ADMINFILE, 'r')
users = ast.literal_eval(fp.read())
if not parameters:
if not source[1] in users:
UserId = "{}".format(source[1])
users.append(UserId)
write_file(ADMINFILE,str(users))
fp.close()
reply(type, source, u"test")
else:
reply(type, source, u"test")
register_command_handler(view_menu, 'test', ['info','muc','all'], 0, '')
Run Code Online (Sandbox Code Playgroud)
请问我该如何解决这个问题.
谢谢
我为我的问题制作了这个示例代码.我需要离开True
或False
停止循环,但我不知道如何?
def test():
list = [u"sam", u"jay", u"jean", u"smo", u"gon", u"bil"]
user = u"jean"
for x in list:
if user==x:
print True
else:
print False
test()
Run Code Online (Sandbox Code Playgroud)
输出:
False
False
True
False
False
False
Run Code Online (Sandbox Code Playgroud)