2013-02-07 6 views
5

을 완료 할 때까지 나는 파일이 다음 새 파일을 쓰기 시작 복사 할 때까지 기다립니다shutil.copyfile가

그러나
shutil.copyfile("largefile","newlargefile") 
nwLrgFile=open("newlargefile",'a') 
nwLrgFile.write("hello\n") 

, 위 hello 파일이 끝나기 전에 기록됩니다 수행 할 때. copyfile이 완료되었는지 확인하는 올바른 방법은 무엇입니까?

내가보기에 모든 답변이 shutil.copyfile 블록 또는 잠금 장치이며 문제가되어서는 안된다고 보았습니다. 그리고 아직 그렇습니다. 도와주세요! 대신 직접 copyfileobj를 사용

+1

의심. 문제를 보여주는 자체 포함 된 예제를 제공 할 수 있습니까? – nneonneo

답변

2

시도 :

with open('largefile', 'r') as f1, open('newlargefile', 'w') as f2: 
    shutil.copyfileobj(f1, f2) 
    f2.write('hello')