当前位置:网站首页>Python Gadgets: code conversion

Python Gadgets: code conversion

2020-11-08 10:29:57 Carltmf.

background :

         Data warehouse project , from Linux The exported file is UTF-8 code , and Windows The default encoding is GBK. When it comes to the mutual transmission of files containing Chinese characters, the file is garbled , To speed up work efficiency , adopt python Realize the conversion between codes .

Language :

        Python3

Script :

 1 import codecs
 2 def ReadFile(filePath,encoding):
 3     with codecs.open(filePath,"r",encoding) as f:
 4         return f.read()
 5  
 6 def WriteFile(filePath,data,encoding):
 7     with codecs.open(filePath,"w",encoding) as f:
 8         f.write(data)
 9  
10 def Encode_Convert(src,dst):
11     content = ReadFile(filePath=src[0],encoding=src[1])
12     WriteFile(filePath=dst[0],data=content,encoding=dst[1])
13     
14 src=input("input src: ").split(",")
15 dst=input("input dst: ").split(",")
16 Encode_Convert(src,dst)

 

版权声明
本文为[Carltmf.]所创,转载请带上原文链接,感谢