This commit is contained in:
guanjihuan 2022-02-16 19:16:24 +08:00
parent e162cf0def
commit 50845d74a0
2 changed files with 14 additions and 0 deletions

View File

@ -0,0 +1,4 @@
import guan
guan.change_directory_by_replacement(current_key_word='codes', new_key_word='data')
with open('data.txt', 'w') as f: # 保存数据
f.write('Hello world')

View File

@ -0,0 +1,10 @@
import os
code_path = os.getcwd() # 查看当前代码文件的路径
data_path = code_path.replace('\\', '/') # \改为/,防止路径报错
data_path = code_path.replace('codes', 'data') # 把路径中codes改为data
if os.path.exists(data_path) == False: # 如果文件夹不存在,新建文件夹
os.makedirs(data_path)
os.chdir(data_path) # 转到数据的存放路径
with open('data.txt', 'w') as f: # 保存数据
f.write('Hello world')