Parcourir la source

add python_changetxt.py.

xdc il y a 5 ans
Parent
commit
46ea723f8e
1 fichiers modifiés avec 13 ajouts et 0 suppressions
  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)