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 not work. The thing is I need that list as an integer-list in another place in the code (when comparing values in an if-statement), and I've tried to convert the integer-list to a string-list, but then the numbers gets placed on separate lines like for e.g.,
I have to write 2016 in one line:
2016
but, it gets like this
2
0
1
6
here is the code for writing to a text file:
print("write year: ") year.append(int(input()))
...some code that needs the list year as an integer...
year_string = str(year)
with open('movietitle.txt', 'w') as file:
file.write('\n'.join(movietitle))
with open('year_string.txt', 'w') as file:
file.write('\n'.join(year_string))
with open('genre.txt', 'w') as file:
file.write('\n'.join(genre))
with open('review.txt', 'w') as file:
file.write('\n'.join(review))