import json numbers = [2, 4, 5, 7, 1, 9] filename = 'numbers.txt' with open(filename, 'w') as f_obj: json.dump(numbers, f_obj)