I need to write an array of integers into a text file, but the formatted solution is adding the comma after each item and I'd like to avoid the last one.
The code looks like this:
with open(name, 'a+') as f:
line = ['FOO ', description, '|Bar|']
f.writelines(line)
f.writelines("%d," % item for item in values)
f.writelines('\n')
Each line starts with a small description of what the array to follow contains, and then a list of integers. New lines are added in the loop as they become available.
The output I get looks something like this:
FOO description|Bar|274,549,549,824,824,824,824,824,794,765,765,736,736,736,736,736,
And I would like to have it look like this, without the last comma:
FOO description|Bar|274,549,549,824,824,824,824,824,794,765,765,736,736,736,736,736
I was unable to find a solution that would work with the writelines() and I need to avoid lengthy processing in additional loops.