I'm playing around with try: and am expecting 'Hello' to be written to testfile.tx. However when I check the file, 'Hello' doesn't appear. What is wrong with my code?
try: f = open('testfile.txt', 'w') f.write('Hello') except TypeError: print ('There was a type error') except OSError: print('There was an OS error') finally: print('I always run')
finally: f.close()with open(...)altogether.import os; print(os.getcwd())