소스 검색

add python_changetxt.py.

xdc 5 년 전
부모
커밋
46ea723f8e
1개의 변경된 파일13개의 추가작업 그리고 0개의 파일을 삭제
  1. 13 0
      python_changetxt.py

+ 13 - 0
python_changetxt.py

@@ -0,0 +1,13 @@
+def alter(file,old_str,new_str):
+  file_data = ""
+  with open(file, "r", encoding="utf-8") as f:
+    for line in f:
+      if old_str in line:
+        line = line.replace(line,new_str)
+      file_data += line
+  with open(file,"w",encoding="utf-8") as f:
+    f.write(file_data)
+    f.close()
+code_pro = 'mycode'
+code = f"secret_code = '{code_pro}'"
+alter("/Users/xc/Desktop/conf.toml", "secret_code", code)