1
나는이 파이썬에서 다음 스크립트 : 나는 매개 변수로 존재하지 않는 파일 이름으로 스크립트를 시작하면 예상대로예외가 지연 발생합니다
import sys
for filename in sys.argv:
with open(filename, mode='r') as f:
print("Foobar")
, 나는 예외를 얻을. 그러나 print()
은 아직 실행되지 않았지만 예상대로 실행됩니다.
Foobar
Traceback (most recent call last):
File "home/bin/ksp-increment-build", line 16, in <module>
with open(filename, mode='r') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'asdads'
왜인가요?
if len (sys.argv)> 1 : (sys.argv [1 :])에있는 파일의 경우 : str (os.walk())의 파일 : – dsgdfg