Python文件拷贝函数
生活随笔
收集整理的這篇文章主要介紹了
Python文件拷贝函数
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
test.txt文件內(nèi)容如下:
one two three four five 代碼的功能為把test.txt內(nèi)容拷貝到copy.txt文件中代碼如下:
def main():infile = open("test.txt", "r")outfile = open("copy.txt", "w")countLines = countChars = 0for line in infile:countLines += 1countChars += len(line)outfile.write(line)print(countLines, "lines and", countChars, "chars copied")infile.close()outfile.close()main()總結(jié)
以上是生活随笔為你收集整理的Python文件拷贝函数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 图像处理 --- 三、图像变换 3.2
- 下一篇: python学习---常见的内置字符串(