Browse Source

去掉readfile函数。

liuyuqi 7 years ago
parent
commit
542354ffe6
1 changed files with 9 additions and 14 deletions
  1. 9 14
      python/convert.py

+ 9 - 14
python/convert.py

@@ -4,18 +4,6 @@ import chardet
 import codecs
 
 
-def ReadFile(filePath, dst, encoding="gbk"):
-    with codecs.open(filePath, "r", encoding) as f:
-        try:
-            WriteFile(dst, f.read(), encoding="utf-8")
-            try:
-                print(filePath + "  " + encoding + " to utf-8  converted!")
-            except Exception:
-                print("print error")
-        except Exception:
-            print(filePath +"  "+ encoding+ "  read error")
-
-
 def WriteFile(filePath, u, encoding="utf-8"):
     with codecs.open(filePath, "w", encoding) as f:
         f.write(u)
@@ -27,8 +15,15 @@ def GBK_2_UTF8(src, dst):
     coding = chardet.detect(f.read())["encoding"]
     f.close()
     if coding != "utf-8":
-        ReadFile(src, dst, encoding=coding)
-
+        with codecs.open(src, "r", encoding) as f:
+            try:
+                WriteFile(dst, f.read(), coding="utf-8")
+                try:
+                    print(src + "  " + coding + " to utf-8  converted!")
+                except Exception:
+                    print("print error")
+            except Exception:
+                print(src +"  "+ coding+ "  read error")
 
 # 递归遍历rootdir目录,把目录中的*.java编码由gbk转换为utf-8
 def ReadDirectoryFile(rootdir):