Python Exception Handling

Python exceptions try/except (example from my static site generator project):

def write_about_json(project_name, about_dictionary):

try:

with open(‘projects/’ + project_name + ‘/settings/about.json’, ‘w’) as json_file:

json.dump(about_dictionary, json_file)

except IOError:

print(“Error: failed to write to about.json”)

sys.exit()

← Previous | Next →

Python Topic List

Main Topic List

Leave a Reply

Your email address will not be published. Required fields are marked *