[Tutor] Terminating "\M" characters with regard to csv.DictWriter
boB Stepp
robertvstepp at gmail.com
Sun Aug 8 22:57:21 EDT 2021
On 21/08/08 07:05PM, Alex Kleider wrote:
>Using the csv module's DictReader and DictWriter to update data in a file
>one of my functions is as follows:
>
>def dict_write(f, fieldnames, iterable):
> """
> Writes all records received from <iterable> into a new csv
> file named <f>. <fieldnames> defines the record keys.
> Code writen in such a way that <iterable> could be
> a generator function.
> """
> with open(f, 'w', newline="") as outfile_obj:
> print("Opening {} for output...".format(outfile_obj.name))
> dict_writer = csv.DictWriter(outfile_obj, fieldnames)
> dict_writer.writeheader()
> for record in iterable:
> dict_writer.writerow(record)
>
>All works as I would like except that the newly generated csv file has a
>'\M' at the end of each line. I only became aware of this when doing a
In a comment to the answer at
https://unix.stackexchange.com/questions/82536/showing-type-of-newline-character-in-emacs
it says:
<quote>
And if you set the buffer to Unix line endings when the file contains DOS line
endings, it will show the CRs as \Ms at the end of each line – Michael Mrozek
Jul 10 '13 at 19:53
</quote>
I imagine emacs and vim display things similarly and I know you use Linux.
Could this be it?
--
Wishing you only the best,
boB Stepp
More information about the Tutor
mailing list