​python创建文件
更新:HHH   时间:2023-1-7


python创建文件

>>>def make_take_file():

a=open('D:\\test01.txt','w')

a.write("This is a test to create a new text file")

a.close()

>>>make_take_file()


open后面的参数w表示向文件中写数据,如果没有指定该参数,python认为是打算从文件中读数据,若文件不存在,将抛出异常。如果文件已存在,则将新建一个同名文件将原文件覆盖。


返回编程语言教程...