本篇文章给大家谈谈如何通过python新建一个文件中的文件,以及如何通过python新建一个文件夹并命名,希望对各位有所帮助,不要忘了收藏本站喔。

文件的创建
创立了一个名为student.text的文件
filename='student.text'
stu_txt = open(filename, 'a', encoding='utf-8')
文件的打开
对文件的读写操作
file=open('aa.txt','r')
print(file.readlines())
file.close()
文件的复制操作
src_file=open('james.png','rb') #把图片变成010101二进制读到
tar_file=open('jamesCopy.png','wb')
tar_file.write(src_file.read())
src_file.close()
tar_file.close()
文件读写的with操作
#with语句-不用再写file.close
with open('james.png','rb') as src_file:
with open('toCopy.png','wb') as tar_file:
tar_file.write(src_file.read())
本文详细介绍了如何使用Python进行文件的创建(包括文本文件和文件夹)、打开、读写、复制以及利用with语句进行更便捷的文件操作,旨在帮助读者掌握基础的文件处理技巧。
11万+

被折叠的 条评论
为什么被折叠?



