stackoverflowのおかげで、ファイルを読み取ってコピーすることができます。ただし、画像ファイルを一度に1行ずつ読み取る必要があり、バッファ配列は3,000整数を超えることはできません。行を分離して読み取り、コピーするにはどうすればよいですか?これを実行するための最良の方法ですか?
@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()が整数ではなく文字列を返すのではないかと心配しています。また、処理する整数の数を制限するにはどうすればよいですか?