python3基础——文件

file = open("/Users/yanghui/Study/python/testFile",'w') //可以指定文件保存地址,如果没有该文件则创建该文件
file.write('Test to save file to new') //写入内容

file.close() //操作完文件后一定要关闭,释放内存资源


file = open("/Users/yanghui/Study/python/testFile",'a') #文件后追加内容
file.write('\nTest to add file')

file.close()

file = open("/Users/yanghui/Study/python/testFile",'r').read() #读取文件内容
print(file) #打印读取到的文件内容


猜你喜欢

转载自blog.csdn.net/melody113026/article/details/80745785