I have following script in Python 3.2.3:
try:
file = open(\'file.txt\', \'r\')
except IOError:
print(\'There was an error opening the file!\')
sys.ex
Using sys.exit() is fine. If you're that concerned with output, you can always add an extra try/except block within your error handling section to catch the SystemExit and stop it from being directed to console output.
try:
file = open('file.txt', 'r')
except IOError:
try:
print('There was an error opening the file!')
sys.exit()
except SystemExit:
#some code here that won't impact on anything