empty file python code example Example 1: python empty text file open('file.txt', 'w').close() Example 2: python os make empty file open(x, 'a').close()