利用python读取带有中文的字符串,和将带有中文的字符串写到txt文件中

    xiaoxiao2021-03-25  87

    从txt文件中读入

    filePath为文件路径,encoding='utf-8'表示读进来来后以utf-8进行编码 f = open(filePath,encoding='utf-8')

    写到txt文件中:

    用的是python3.5版本: 如果只是使用系统默认的open()方法,只能写入ascii码,要读入中文,可以使用codecs模块:

     import codecs return=u"中文" file = codecs.open(filePatn,'w','utf-8')

    转载请注明原文地址: https://ju.6miu.com/read-25451.html

    最新回复(0)