小编yuy*_*b0y的帖子

UnicodeEncodeError:'ascii'编解码器无法编码位置0-3中的字符:序数不在范围内(128)

当我运行我的代码时,我收到此错误:

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)

请问我该如何解决这个问题.

谢谢

python python-2.7

9
推荐指数
3
解决办法
2万
查看次数

停止for循环,只是变为true或false

我为我的问题制作了这个示例代码.我需要离开TrueFalse停止循环,但我不知道如何?

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)

python python-2.7

-1
推荐指数
1
解决办法
86
查看次数

标签 统计

python ×2

python-2.7 ×2