python创建txt文件的方法(包括写入和修改) 新建、写入: # 创建一个txt文件,文件名为first file,并向文件写入msg def File_New(name, msg): desktop_path = “路径” #文件路径 full_path = desktop_path + name + ‘.txt’ # 也可以是.doc file = open(full_path,’w’) file.write(msg) file.clos...
python有一个内置的函数open,该函数可以打开文件 使用“open('文件名','w')”语句以写模式打开文件,如果没有该文件,就会直接创建一个文件并打开,这样txt文件就创建成功了 示例如下: 完整代码: file =open('xx.txt','w') file.close() AI代码助手复制代码 执行open函数之前 执行open函数之后 感谢你能够认真阅...