感谢stackoverflow,我能够读取和复制文件。但是,我需要一次读取一行图片文件,并且缓冲区数组不能超过3,000个整数。我将如何分隔线条,阅读它们,然后复制它们?这是执行此操作的最佳方式吗?如何在python中读取和划分文件的各个行?
这里是我的代码,@Chayim的礼貌:
import os
import sys
import shutil
import readline
source = raw_input("Enter source file path: ")
dest = raw_input("Enter destination path: ")
file1 = open(source,'r')
if not os.path.isfile(source):
print "Source file %s does not exist." % source
sys.exit(3)
file_line = infile.readline()
try:
shutil.copy(source, dest)
infile = open(source,'r')
outfile = open(dest,'r')
file_contents = infile.read()
file_contents2 = outfile.read()
print(file_contents)
print(file_contents2)
infile.close()
outfile.close()
except IOError, e:
print "Could not copy file %s to destination %s" % (source, dest)
print e
sys.exit(3)
我加 file_line = infile.readline() 但我担心infile.readline()将返回一个字符串,而不是整数。另外,我如何限制它处理的整数数量?
你的问题具体是什么?你想要上面的程序做什么? – theAlse 2013-03-06 15:43:54