import os
# 創建多級文件(不含文件)
def create_dir(file_path):
if os.path.exists(file_path) is False:
os.makedirs(file_path)
if __name__ == '__main__':
# 創建絕對路徑文件(硬盤)
create_dir('D:/aaa')
with open('D:/aaa/a.txt', 'w', encoding='utf-8') as f:
f.write('七夕節')
# 創建相對路徑文件(項目根目錄)
with open('a.txt', 'w', encoding='utf-8') as f:
f.write('七夕節')