summaryrefslogtreecommitdiff
path: root/04-CustomLibrary/FileLibrary/filetool.py
diff options
context:
space:
mode:
authordongxiaoyan <[email protected]>2020-04-01 12:42:05 +0800
committerdongxiaoyan <[email protected]>2020-04-01 12:42:05 +0800
commitacc676857bd85512f344a8d06aa1ae8846e7c0db (patch)
treef2a7e19139d7f763e699ae10a997184c168fed76 /04-CustomLibrary/FileLibrary/filetool.py
first init project codeHEADmaster
Diffstat (limited to '04-CustomLibrary/FileLibrary/filetool.py')
-rw-r--r--04-CustomLibrary/FileLibrary/filetool.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/04-CustomLibrary/FileLibrary/filetool.py b/04-CustomLibrary/FileLibrary/filetool.py
new file mode 100644
index 0000000..56eadcf
--- /dev/null
+++ b/04-CustomLibrary/FileLibrary/filetool.py
@@ -0,0 +1,27 @@
+#coding=utf-8
+import sys
+reload(sys)
+sys.setdefaultencoding("utf-8")
+
+""" 变量文件操作 """
+
+class filetool():
+ def __init__(self):
+ pass
+
+ def alter_dict(self, path, k, v):
+ data = ''
+ flag = True
+ key = '${%s}' % (k)
+ add = key + '\t%s' % (v) + '\n'
+ with open(path, 'r+') as f:
+ for line in f.readlines():
+ if(line.find(key + '\t') == 0):
+ line = add
+ flag = False
+ data += line
+ if(flag):
+ data += add
+ print data
+ with open(path, 'w+') as f:
+ f.writelines(data) \ No newline at end of file