蓝绝

博客园 首页 新随笔 联系 订阅 管理

 

file=open('a.txt','w')     #a.txt 如果没有就会创建新的文件
file.write('python')       #文件写入python
file.close()

file=open('a.txt','a')   #  a 文件追加内容
file.write('python1')
file.close()

file=open('a.txt','r')  #  读取a.txt 内容
print(file.readline()) 
file.close()
F:\python3\python_3.8.3\python.exe E:/PycharmProjects/pythonProject/demon1/chap2/demo1.py
pythonpython1

进程已结束,退出代码0

#rb  wb  二进制方式读取复制图片

 

src_file=open('logo.png','rb')            #rb用二进制方式打开文件,读取文件
target_file=open('copylogo.png','wb')     #wb用二进制只写模式打开文件
target_file.write(src_file.read())        #把读取的文件内容写入target_file
target_file.close()                       #关闭文件
src_file.close()                          #关闭文件

 

#  + 以读写模式打开

 

 

posted on 2022-10-03 22:05  蓝绝  阅读(49)  评论(0编辑  收藏  举报