1 Star 0 Fork 0

zhao-shu-bo/czsf

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
12 1.35 KB
Copy Edit Raw Blame History
zhao-shu-bo authored 2021-11-15 20:53 +08:00 . add 12.
f = open('text.txt','w+')
f.write('World')
print('1.创建text.txt文件,World写入文件')
f = open('text.txt','r+')
f.write('Hello')
print('2.打开text.txt文件,Hello覆盖文件内容')
f = open('text.txt','a')
f.write(' ')
print('3.打开text.txt文件,在文件尾部追加空格" "')
fname = '/home/fan/作业/12/text.txt'
f = open(fname,'a+')
f.write('World')
print('4.打开text.txt,在文件尾部追加World')
f_name = 'text.txt'
f = None
try:
f = open(f_name)
print('打开文件成功')
content= f.read()
print(content)
except FileNotFoundError as e:
print('文件不存在,请先使用12.1.py程序创建文件')
except OSError as e:
print('处理OSError异常')
finally:
if f is not None:
f.close()
print('关闭文件成功')
f_name = 'text.txt'
with open('text.txt') as f:
content = f.read()
print(content)
f_name = 'src_file.txt'
with open(f_name,'r',encoding ='gbk') as f:
lines = f.readlines()
copy_f_name = 'dest_file.txt'
with open(copy_f_name,'w',encoding = 'utf-8') as copy_f:
copy_f.writelines(lines)
print('复制成功')
f_name = 'logo.png'
with open(f_name,'rb') as f:
b = f.read()
copy_f_name = 'logo2.png'
with open(copy_f_name,'wb') as copy_f:
copy_f.write(b)
print('文件复制成功')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhao-shu-bo/czsf.git
git@gitee.com:zhao-shu-bo/czsf.git
zhao-shu-bo
czsf
czsf
master

Search