Link to home
Start Free TrialLog in
Avatar of fb1990
fb1990

asked on

Python to_csv output quoting issue

Hello Experts,

I have a piece of Python code that is importing data and exporting it as a.csv. But I am having.csv output quoting issues when there is an apostrophe (') and double quote ("). Can someone please help me modify the code?


I have attached a sample of the data and the code snippet below:


 with open(f"{here}/records.csv", "w", encoding="utf-8", newline='') as f:

        writer = csv.writer(f, escapechar='"', quotechar="'")

        writer.writerow(["ID", "Application ID", "Application name", "Review Date", "Review Title", "Review Content", "Author Name", "Stars", "Version", "Store"])

        writer.writerows(records)


Avatar of pepr
pepr

What happens when you use only writer = csv.writer(f) ?
Avatar of fb1990

ASKER

Thanks, @pepr.  i got this error

AttributeError: '_csv.writer' object has no attribute 'writeheader'
Is the attached file what you are importing or what's being exported by your code?

What exactly do you have in records?
ASKER CERTIFIED SOLUTION
Avatar of pepr
pepr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fb1990

ASKER

@Pepr. Thanks for your help.  I sent a message to your inbox.