Issues Parsing CSV Files with Varying Quote Styles in Python - working with advanced patterns
I can't seem to get I'm attempting to parse a CSV file in Python using the built-in `csv` module, but I'm running into some issues due to inconsistent quoting styles across different rows in the file. Some rows are quoted with double quotes, while others use single quotes, and a few have no quotes at all. I'm using Python 3.10 and here's a snippet of the code I've implemented: ```python import csv with open('data.csv', 'r') as file: reader = csv.reader(file, quotechar='"') # trying default double quote for row in reader: print(row) ``` This works fine for rows with double quotes, but I'm working with a question when a row contains single quotes. The output is not as expected when a single-quoted string appears in a row, and it's treating it as separate values instead of a single entry. For instance, a row like this: ``` John, 'Doe', 30 ``` gets parsed into: ``` ['John', "'Doe'", '30'] ``` Instead, I want it to be: ``` ['John', 'Doe', '30'] ``` I've tried setting the `quotechar` to single quotes, but then it fails to handle double quotes properly. Is there a way to address this scenario in a more flexible manner? I've looked into using `pandas` as well, but I want to stick with the built-in module for this task. Any advice on how to handle different quoting styles effectively would be greatly appreciated! I've been using Python for about a year now.