Python Forum
CSV not printing apostrophe correctly
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CSV not printing apostrophe correctly
#4
Use utf-8 both when read and write file,usually now these days is Python not the problem,
but outside stuff like files(use utf-8),Os,Editors...
When moved to Python 2 to 3 Unicode was one biggest changes.

Example file saved as utf-8:
some.csv
Output:
administrator’s, Mac Boat, ⚓️ Rain, ☂️ はるさんハウスはどこですか, jap
import csv

with open('some.csv', newline='', encoding='utf-8') as f, open('out.csv', 'w', encoding='utf-8') as f_out:
    reader = csv.reader(f)
    writer = csv.writer(f_out)
    for row in reader:
        print(row[0], row[1])
        writer.writerow(row)
Output:
administrator’s Mac Boat ⚓️ Rain ☂️ はるさんハウスはどこですか jap
In out.csv:
Output:
administrator’s, Mac Boat, ⚓️ Rain, ☂️ はるさんハウスはどこですか, jap
Reply


Messages In This Thread
RE: CSV not printing apostrophe correctly - by snippsat - Aug-18-2022, 05:34 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,835 Sep-05-2019, 12:37 AM
Last Post: Exsul
  If statement containing apostrophe AshBax 11 7,914 Jul-09-2019, 01:34 PM
Last Post: AshBax
  Print Not Printing Correctly kittylexi 3 4,574 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