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认为是打算从文件中读数据,若文件不存在,将抛出异常。如果文件已存在,则将新建一个同名文件将原文件覆盖。
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认为是打算从文件中读数据,若文件不存在,将抛出异常。如果文件已存在,则将新建一个同名文件将原文件覆盖。