国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Wie erstelle ich UTF-8-Dateien in Python?
三叔
三叔 2017-06-14 10:53:28
0
2
1190
# coding=utf-8 ##以u(píng)tf-8編碼儲(chǔ)存中文字符
import os
import codecs

path = "d:/Python/c.txt"
try:
    f=codecs.open(path,'w', 'UTF-8')
    f.close()
except Exception as e:
    print(e)
os.system('pause')

Python 3.6.1

Der obige Code kann nur Textdateien im ANSI-Format erstellen.

三叔
三叔

Antworte allen(2)
迷茫

其實(shí)題主的代碼可以創(chuàng)建UTF-8的文件,只是由于沒有往文件里寫內(nèi)容,空的txt文件不存在編碼,寫一些UTF字符再試試就OK了

    f=codecs.open(path,'w', 'UTF-8')
    f.write("中文")
    f.close()

再打開c.txt文件就是UTF-8了。
(Python3.4)

小葫蘆

encoding='utf8'

>>> with open('utf8.txt','w', encoding='utf8') as w:
    w.write('以u(píng)tf-8編碼儲(chǔ)存中文字符')

    
14

>>> with open('utf8.txt','r', encoding='utf8') as r:
    print(r.encoding)
    print(r.read())

    
utf8
以u(píng)tf-8編碼儲(chǔ)存中文字符
>>> 
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage