Python文件拷贝函数
生活随笔
收集整理的這篇文章主要介紹了
Python文件拷贝函数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
test.txt文件內容如下:
one two three four five 代碼的功能為把test.txt內容拷貝到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()總結
以上是生活随笔為你收集整理的Python文件拷贝函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 图像处理 --- 三、图像变换 3.2
- 下一篇: OpenCV——图像显示与写入