我如何在python中获得有效的反斜线

问题描述 投票:0回答:1

我有一个编码后的字符串另存为文件中的字符串,如果可以的话,可以更改它。我想读一读,并得到真正的字符串。抱歉,我不能很好地解释xD,这是我的代码:

def saveFile(src, con):
    with open(src, "w") as f:
        f.write(str(con))
        f.close()

...
string = "юра"
saveFile("info", mlistsaver.encode())

这是“信息”文件:b'\xd1\x8e\xd1\x80\xd0\xb0'但是当我使用这个时:

def get(src):
    f = src
    if path.isfile(f):
        with open(f, "r") as f:
            return f.read()
    else:
        return None

...


get("info").encode('iso-8859-1').decode('utf-8')

字符串就是:b'\xd1\x8e\xd1\x80\xd0\xb0'我知道它必须用double \做一些事情,但是我无法解决。如前所述,我可以将字符串保存为所需的任何格式,我认为这样做确实很愚蠢。

谢谢你们!

python-3.x encoding utf-8 byte backslash
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.