open() in Python does not create a file if it doesn’t exist

You should use open with the w+ mode:

file = open('myfile.dat', 'w+')

Leave a Comment