python中文件的讀寫:
? ? 1.文件的寫主要包括兩個方面:目錄(文件夾)和文件叹话,在這兩者結(jié)合朝墩,要使用 \\醉拓。
? ? 2.先創(chuàng)建目錄(需要用到os模塊):
? ? file_path = r"C:\Users\admin\Desktop\test"
? ? if not os.path.exists(file_path):
? ? ? ? os.mkdir(file_path)
? ? 3.打開文件,寫入內(nèi)容:
? ? with open(file_path + '\\teng.csv','wt',encoding='utf-8') as f:
? ? ? ? f.write('要寫入的內(nèi)容')