Python关于文件os操纵
import os
# 获与当前途径
current_path = os.getcwd()
print(current_path)
# 创立文件夹
dir_path一=current_path+"\\wenjianjia"
# 判定文件夹是可存正在,没有存正在则创立
if os.path.exists(dir_path一):
print('文件已经经存正在')
else:
print("没有存正在,在创立")
os.mkdir(dir_path一)
# 创立文件
dir_path =current_path+"\\wenjian.txt"
with open(dir_path,mode="w",encoding='utf⑻') as f:
f.write("汉字")
转自:https://www.cnblogs.com/ngstx/p/15361658.html
更多文章请关注《万象专栏》
转载请注明出处:https://www.wanxiangsucai.com/read/cv3127