나는 3 일을하는 내가 쓰고 파이썬 3 스크립트가 파일을 다운로드 한 후내 스크립트가 아직 다운로드하지 않은 파일의 압축을 풀려고하는 이유는 무엇입니까?</p> <p>1) 데이터 파일이 2를 다운로드 해야하는 Retrosheets를 결정) wget을 만들기 그들 3) 압축 풀기 파일을 검색하고 다운로드 명령 :
파이썬 콘솔에서 각 기능을 테스트 할 때 아무런 문제가 없습니다. 내가 자동으로 모든 일을하려고 할 때, 나는 다음과 같은 출력을 얻을 :
Start Decade: 1930
End Decade: 1950
Creating wget commands...
Commands created...
Downloaded 3 files.
Unzipping files...
Traceback (most recent call last):
File "import_pbp.py", line 54, in <module>
unzip_data(decade_files)
File "import_pbp.py", line 39, in unzip_data
with zipfile.ZipFile('zip' + file, 'r') as zip_ref:
File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5 /lib/python3.5/zipfile.py", line 1009, in __init__
self.fp = io.open(file, filemode)
FileNotFoundError: [Errno 2] No such file or directory: 'zip1930seve.zip'
파일은 콘솔이 출력 후 다운로드됩니다. 파일을 다운로드하기 전에 unzip 함수가 실행 중임을 나타냅니다. 압축 해제 기능을 호출하기 전에 파일을 다운로드하는 방법은 무엇입니까? 아래 코드 :
다운로드 기능 :
# define function to execute the download commands
def download_data(commands):
for command in commands:
os.popen(command)
print('Downloaded ' + str(len(commands)) + ' files.')
압축 해제 기능 :
# Unzip the data files into the 'unparsed' folder.
def unzip_data(file_list):
print('Unzipping files...')
for file in file_list:
with zipfile.ZipFile('zip' + file, 'r') as zip_ref:
zip_ref.extractall('unparsed/')
print(file + ' unzipped')
print('All files unzipped...')
편집 : 응답 in this thread 보았다하지만 그것은 아주 tdelaney 아래처럼 내가 필요로하는지 설명하지 않았다. 그들은 유사하지만, 내 목적에 따라 다르다. 특히 그 질문이 6 살이 기 때문에 그 이후로 언어에 중대한 변화가 있었을 것으로 추측합니다.
편집 2 : 게시물을 줄이기 위해 필수가 아닌 코드를 삭제했습니다.
가능한 중복으로 해당 기능을 구현할 수있다. 명령이 완료 될 때까지 기다리십시오. (http://stackoverflow.com/questions/2837214/python-popen-command-wait-until-the-command-is-finished) – glibdud
'os.popen()'명령은 돌아올 때까지 기다리십시오. – glibdud