python在某個路徑怎么創(chuàng)建text文件?
# 創(chuàng)建一個txt文件,文件名為mytxtfile,并向文件寫入msg
def text_create(name, msg):
desktop_path = "C:\\Users\\Administrator\\Desktop\\" # 新創(chuàng)建的txt文件的存放路徑
full_path = desktop_path + name + '.txt' # 也可以創(chuàng)建一個.doc的word文檔
file = open(full_path, 'w')
file.write(msg) #msg也就是下面的Hello world!
# file.close()
text_create('mytxtfile', 'Hello world!')
# 調用函數(shù)創(chuàng)建一個名為mytxtfile的.txt文件,并向其寫入Hello world!