Im trying to write a text file from a list, it works perfectly with a list of strings, each element gets on a new line. But when I try to write from a list with integers it does
Since you used the variable name year
I think you're trying to convert a string integer of year, so here's how you'd do that. I am also suspect this is the issue because of the odd output you're getting. I also added code on how to one-line convert years to a string version of itself.
year = 1998
with open('year.txt', 'w') as file:
file.write('\n'.join([str(year)]))
years = [1998,1996]
with open('year2.txt', 'w') as file:
file.write('\n'.join(str(year) for year in years))
years = [1998,1996]
with open('year2.txt', 'w') as file:
file.write('\n'.join(years))