import io with open("out.txt", "w+") as fo: fo.write("one\n") fo.write("two\n") fo.write("three four five\n") current_position = fo.seek(500, io.SEEK_SET) print(current_position) # The opened file length is less then 500, and where we set the curser as above. # Python fill all places with null,To my opinion Should Throw compatible Exception # But if we write current_position = fo.seek(5, io.SEEK_End), An Exception will raise