Python Forum
CSV not printing apostrophe correctly
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CSV not printing apostrophe correctly
#5
(Aug-17-2022, 09:18 PM)deanhystad Wrote: Don't use utf-8 encoding. It is too restrictive. You should probably specify a dialect.

Thanks for reply. I have fixed it partly by doing this. I was not encoding the first write as the others below pointed out. I am now doing this.

 with open(full_report_path, 'w',encoding='utf-8') as f:
        writer = csv.writer(f)
        writer.writerow(['High alerts found', len(list_of_high_alerts)])
        writer.writerow(['Medium alerts found', len(list_of_medium_alerts)])
        writer.writerow(report_column_names)
    # Sets the column order
    with open(full_report_path, 'a+', encoding='utf-8', newline='') as output_file:
        dict_writer = csv.DictWriter(output_file, report_column_order)
        dict_writer.writerows(computer_list)
This works fine for Numbers, but Excel is still an issue. Can you please explain a bit more about dialects?
Reply


Messages In This Thread
RE: CSV not printing apostrophe correctly - by bazcurtis - Aug-18-2022, 10:36 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Is it possible to have an apostrophe inside { } in an f-string? Exsul 6 12,849 Sep-05-2019, 12:37 AM
Last Post: Exsul
  If statement containing apostrophe AshBax 11 7,919 Jul-09-2019, 01:34 PM
Last Post: AshBax
  Print Not Printing Correctly kittylexi 3 4,581 Sep-11-2018, 04:38 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020