There seems to something on this topic already (How to replace all those Special Characters with white spaces in python?), but I can\'t figure this simple task out for the l
In addition to the bug pointed out by @Nisan.H and the valid point made by @dckrooney that you may not need to treat the file in a special way in this case just because it is a CSV file (but see my comment below):
writer.writerow()
should take a sequence of strings, each of which would be written out separated by commas (see here). In your case you are writing a single string.input
and through lines
but it only actually reads from input
(therefore the code does not deal with the file as a CSV file anyway).newtext
and writes out each version of that variable. Thus, the first version of newtext
would be 1 character long, the second 2 characters long, the third 3 characters long, etc.Finally, given that a CSV file can have quote marks in it, it may actually be necessary to deal with the input file specifically as a CSV to avoid replacing quote marks that you want to keep, e.g. quote marks that are there to protect commas that exist within fields of the CSV file. In that case, it would be necessary to process each field of the CSV file individually, then write each row out to the new CSV file.