AnsweredAssumed Answered

Python ? Attempting to format new text file

Question asked by mimiller on Dec 6, 2016
Latest reply on Dec 8, 2016 by mimiller

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

Outcomes