This commit is contained in:
2023-11-07 03:38:46 +08:00
parent 1e7c4c0e68
commit bc3890c25b
212 changed files with 0 additions and 0 deletions

View File

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

View File

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

View File

@@ -0,0 +1,9 @@
import os
code_path = os.getcwd() # 当前代码文件的路径
data_path = code_path.replace('\\', '/') # \改为/,防止路径报错
data_path = data_path.replace('code', 'data') # 把路径中code改为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')