여기 파이썬의 바이트의 튜토리얼 코드 :sys 모듈의 사용을 이해하지
Traceback (most recent call last):
File "C:/Python/sysmodulepr.py", line 17, in <module>
sys.exit()
SystemExit
을 :이 코드를 실행하면,이 나타나는 오류가
는import sys
filename = 'poem.txt'
def readfile(filename):
#Print a file to standard output
f = file(filename)
while True:
line = f.readline()
if len(line) == 0:
break
print line,
f.close()
if len(sys.argv) < 2:
print 'No action specified'
sys.exit() //<--This is where the error is occurring
if sys.argv[1].startswith('--'):
option = sys.argv[1][2:] #fetches sys.argv[1] without first 2 char
if option == 'version':
print 'Version 1.2'
elif option == 'help':
print '''\
This program prints files to the standard output.
Any number of files can be specified.
Options include:
--version: Prints the version number
--help: Displays this help'''
else:
print 'Unknown option'
sys.exit()
else:
for filename in sys.argv[1:]:
readfile(filename)
나는 왜 그런지 이해하지 못한다. 도와주세요.
추적없이 끝내려면 [이 질문] (http://stackoverflow.com/questions/1187970/how-to-exit-from-python-without-traceback)을 확인하십시오. – osoner
이 코드를 실행 해 보았습니다. "오류"가 나타나지 않습니다. 아래의 해답은 이것을 실제로 SystemExit 예외로 식별합니다.이 예외는 실제로 오류가 아니지만 프로그램이 종료되기 전에 정리를 수행 할 수있는 고리입니다. 그러나 일반적으로'SystemExit' 예외는 이와 같이 역 추적을하지 않습니다. 여기 뭔가 이상한 일이 있습니다 ... – senderle
사용하는 파이썬의 버전은 무엇입니까? 이것은 일반적인 Python 설치가 아닙니다. 맞습니까? –