I'm using the below code and would like to write the output to a new file and write it all to a single line formatted as such:
'D1_06689','D1_0670',......
infile2 = open(r'C:\tmp\RampWork\OutFile.txt', 'r')
outfile2 = open(r'C:\tmp\RampWork\OutFile2.txt', 'w')
for f in infile2:
outfile2.write("'%s'," % (f))
infile2.close()
infile2.close()
infile2:
D1_06689
D1_06705
D1_06706
D1_06707
D1_06729
D1_06730
D1_06731
D1_06732
D1_06733
D1_06734
D1_07043
D1_07044
D1_07045
D1_07046
D1_07047
D1_07048
D1_07122
D1_07123
outfile2:
'D1_06689
','D1_06705
','D1_06706
','D1_06707
','D1_06729
','D1_06730
','D1_06731
','D1_06732
','D1_06733
','D1_06734
','D1_07043
','D1_07044
','D1_07045
','D1_07046
','D1_07047
','D1_07048
','D1_07122
','D1_07123
','D1_07124
','D1_07125
','D1_07126
','D1_07412
Solved! Go to Solution.
Last kick...
>>> txt = list('abcde')
>>> txt_file = "".join(["'{}', ".format(i) for i in txt])
>>> print(txt_file)
'a', 'b', 'c', 'd', 'e',
>>>
Got it. Thank you very much @Dan Patterson