I have a list,
pList = pickle.load(open('primes.pkl', 'rb'))
with open('primes.txt', 'wt') as output:
print "File saved."
pList=[5, 9, 2, -1, 0]
#Code to save it to file, each object on a new line
Simply open your file, join your list with the desired delimiter, and print it out.
outfile = open("file_path", "w") print >> outfile, "\n".join(str(i) for i in your_list) outfile.close()
Since the list contains integers, it's needed the conversion. (Thanks for the notification, Ashwini Chaudhary).
No need to create a temporary list, since the generator is iterated by the join method (Thanks, again, Ashwini Chaudhary).