Your code is blanking out your file:

import csv
workingdir = "C:\Mer\Ven\sample"
csvfile = workingdir+"\test3.csv"
f=open(csvfile,'wb') # opens file for writing (erases contents)
csv.writer(f, delimiter =' ',quotechar =',',quoting=csv.QUOTE_MINIMAL)

if you want to read the file in, you will need to use csv.reader and open the file for reading.

import csv
workingdir = "C:\Mer\Ven\sample"
csvfile = workingdir+"\test3.csv"
f=open(csvfile,'rb') # opens file for reading
reader = csv.reader(f)
for line in reader:
    print line

If you want to write that back out to a new file with different delimiters, you can create a new file and specify those delimiters and write out each line (instead of printing the tuple).

Answer from underrun on Stack Overflow
🌐
Python
docs.python.org › 3 › library › csv.html
csv — CSV File Reading and Writing
The Dialect class is a container class whose attributes contain information for how to handle doublequotes, whitespace, delimiters, etc. Due to the lack of a strict CSV specification, different applications produce subtly different CSV data. Dialect instances define how reader and writer instances ...
Discussions

Made a csv parser library which automatically detects delimiter and start and end of data
This post was mass deleted and anonymized with Redact divide wrench hungry support different longing juggle carpenter point engine More on reddit.com
🌐 r/Python
16
17
May 31, 2023
python - Can I import a CSV file and automatically infer the delimiter? - Stack Overflow
I used this with Python 3.5 and it worked this way. ... I don't think there can be a perfectly general solution to this (one of the reasons I might use , as a delimiter is that some of my data fields need to be able to include ;...). A simple heuristic for deciding might be to simply read the first line (or more), count how many , and ; characters it contains (possibly ignoring those inside quotes, if whatever creates your .csv ... More on stackoverflow.com
🌐 stackoverflow.com
Import csv with multiple kinds of delimiters
The Sniffer class from the csv module is available for this. More on reddit.com
🌐 r/django
6
9
January 6, 2021
Saving to CSV with space after delimiter
You can just set delimiter=", ", but keep in mind that if you read a, b c, d e, f as CSV in any other application, you'll get ["a", " b c", " d e", " f"] (note the spaces). That's part of the CSV format. Also, post questions in r/learnpython next time please. More on reddit.com
🌐 r/Python
5
1
January 17, 2017
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.read_csv.html
pandas.read_csv — pandas 3.0.4 documentation - PyData |
If you want to pass in a path object, pandas accepts any os.PathLike. By file-like object, we refer to objects with a read() method, such as a file handle (e.g. via builtin open function) or StringIO. ... Character or regex pattern to treat as the delimiter. If sep=None, the C engine cannot ...
🌐
Medium
medium.com › @AlexanderObregon › how-to-read-and-write-csv-files-in-python-b84fe274d51a
How to Read and Write CSV Files in Python | Medium
October 26, 2024 - By passing the delimiter=';' argument, the csv.reader() can correctly split each row based on the semicolon, making it easy to work with non-standard CSV formats.
🌐
Real Python
realpython.com › python-csv
Reading and Writing CSV Files in Python – Real Python
January 25, 2023 - The reader object can handle different styles of CSV files by specifying additional parameters, some of which are shown below: delimiter specifies the character used to separate each field.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Read and Write CSV Files in Python | note.nkmk.me
August 6, 2023 - By setting delimiter=' ', elements are split at each space and correctly retrieved. with open('data/src/sample.txt') as f: reader = csv.reader(f, delimiter=' ') l = [row for row in reader] print(l) # [['11', '12', '13', '14'], ['21', '22', '23', ...
🌐
Analytics Vidhya
analyticsvidhya.com › home › data analysis & processing using delimiters in pandas (updated 2026)
Pandas Read CSV Delimiter: A Comprehensive Guide (2026)
December 27, 2025 - Q2. How do I read a CSV file with delimiter in Python? A. Use csv.reader with delimiter argument (basic).
Find elsewhere
🌐
PDFTables
pdftables.com › blog › csv-change-delimiter-excel
How to change the delimiter in a CSV file — PDFTables
I will be changing the delimiter in a sample invoice from a freight company that has been converted from PDF to CSV using PDFTables.com. Create a new Python file in the location where your CSV file is saved. Make sure the file is saved as .py format and use a file name of your choice. Add the following code to the new file: import csv reader = csv.reader(open("freight_invoice.csv", "rU"), delimiter=',') writer = csv.writer(open("output.txt", 'w'), delimiter=';') writer.writerows(reader) print("Delimiter successfully changed")
🌐
Stack Abuse
stackabuse.com › reading-and-writing-csv-files-in-python
Reading and Writing CSV Files in Python
January 9, 2026 - As we can see from the code above, we have modified the third line of code by adding the delimiter parameter and assigning a value of '/' to it. This tells the method to treat all '/' characters as the separating point between column data. We have also added the quoting parameter and assigned it a value of csv.QUOTE_NONE, which means that the method should not use any special quoting while parsing. As expected, the result is similar to the previous example: $ python reader2.py ['1', '2', '3'] ['Good morning', 'Good afternoon', 'Good evening']
🌐
Python Module of the Week
pymotw.com › 2 › csv
csv – Comma-separated value files - Python Module of the Week
$ python csv_list_dialects.py ['excel-tab', 'excel'] Suppose instead of using commas to delimit fields, the input file uses |, like this: "Title 1"|"Title 2"|"Title 3" 1|"first line second line"|08/18/07 · A new dialect can be registered using the appropriate delimiter: import csv csv.register_dialect('pipes', delimiter='|') with open('testdata.pipes', 'r') as f: reader = csv.reader(f, dialect='pipes') for row in reader: print row
🌐
Vertabelo Academy
academy.vertabelo.com › course › python-csv › reading › reading › changing-the-delimiter
Read and Write CSV in Python | Learn Python | Vertabelo Academy
You can check its contents in the Datasets tab. Semicolons are used as delimiters in this file. Your task is to calculate and print the average rent price of this set of properties.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-read-a-csv-file-to-a-dataframe-with-custom-delimiter-in-pandas
How to read a CSV file to a Dataframe with custom delimiter in Pandas? - GeeksforGeeks
July 15, 2025 - # Importing pandas library import pandas as pd # Load the data of example.csv # with '_' as custom delimiter # into a Dataframe df df = pd.read_csv('example2.csv', sep = '_', engine = 'python') # Print the Dataframe df
🌐
Python
pythonprogramminglanguage.com › read-csv
How to Read a CSV File in Python - Python
Python comes with a module to parse csv files, the csv module. You can use this module to read and write data, without having to do string operations and the like. Lets get into how to read a csv file. You can use the csv module. The module is already installed, just import it with import csv. Then you’ll want to open the csv file, you can with: Then create a reader object csv.reader() where the parameters are the filename and the delimiter...
🌐
w3resource
w3resource.com › python-exercises › csv › python-csv-exercise-2.php
Python: Read a given CSV file having tab delimiter - w3resource
July 22, 2025 - Write a Python program to read a given CSV file having tab delimiter. ... import csv with open('countries.csv', newline='') as csvfile: data = csv.reader(csvfile, delimiter = '\t') for row in data: print(', '.join(row))
🌐
Reddit
reddit.com › r/python › made a csv parser library which automatically detects delimiter and start and end of data
r/Python on Reddit: Made a csv parser library which automatically detects delimiter and start and end of data
May 31, 2023 -

For most purposes, just passing the file path will be sufficient and you will have a pandas data frame of you data. Automatically neglects the random extra information at the top and bottom of a file. Also works with those annoying delimiter within quotes thingies (ex: you have a comma delimiter and one field is “John, Andrew and Steven”). It is on PyPI so you can download it with pip.

https://github.com/Oddball777/csv-scavenger

Top answer
1 of 6
65

The csv module seems to recommend using the csv sniffer for this problem.

They give the following example, which I've adapted for your case.

with open('example.csv', 'rb') as csvfile:  # python 3: 'r',newline=""
    dialect = csv.Sniffer().sniff(csvfile.read(1024), delimiters=";,")
    csvfile.seek(0)
    reader = csv.reader(csvfile, dialect)
    # ... process CSV file contents here ...

Let's try it out.

[9:13am][wlynch@watermelon /tmp] cat example 
#!/usr/bin/env python
import csv

def parse(filename):
    with open(filename, 'rb') as csvfile:
        dialect = csv.Sniffer().sniff(csvfile.read(), delimiters=';,')
        csvfile.seek(0)
        reader = csv.reader(csvfile, dialect)

        for line in reader:
            print line

def main():
    print 'Comma Version:'
    parse('comma_separated.csv')

    print
    print 'Semicolon Version:'
    parse('semicolon_separated.csv')

    print
    print 'An example from the question (kingdom.csv)'
    parse('kingdom.csv')

if __name__ == '__main__':
    main()

And our sample inputs

[9:13am][wlynch@watermelon /tmp] cat comma_separated.csv 
test,box,foo
round,the,bend

[9:13am][wlynch@watermelon /tmp] cat semicolon_separated.csv 
round;the;bend
who;are;you

[9:22am][wlynch@watermelon /tmp] cat kingdom.csv 
ReleveAnnee;ReleveMois;NoOrdre;TitreRMC;AdopCSRegleVote;AdopCSAbs;AdoptCSContre;NoCELEX;ProposAnnee;ProposChrono;ProposOrigine;NoUniqueAnnee;NoUniqueType;NoUniqueChrono;PropoSplittee;Suite2LecturePE;Council PATH;Notes
1999;1;1;1999/83/EC: Council Decision of 18 January 1999 authorising the Kingdom of Denmark to apply or to continue to apply reductions in, or exemptions from, excise duties on certain mineral oils used for specific purposes, in accordance with the procedure provided for in Article 8(4) of Directive 92/81/EEC;U;;;31999D0083;1998;577;COM;NULL;CS;NULL;;;;Propos* are missing on Celex document
1999;1;2;1999/81/EC: Council Decision of 18 January 1999 authorising the Kingdom of Spain to apply a measure derogating from Articles 2 and 28a(1) of the Sixth Directive (77/388/EEC) on the harmonisation of the laws of the Member States relating to turnover taxes;U;;;31999D0081;1998;184;COM;NULL;CS;NULL;;;;Propos* are missing on Celex document

And if we execute the example program:

[9:14am][wlynch@watermelon /tmp] ./example 
Comma Version:
['test', 'box', 'foo']
['round', 'the', 'bend']

Semicolon Version:
['round', 'the', 'bend']
['who', 'are', 'you']

An example from the question (kingdom.csv)
['ReleveAnnee', 'ReleveMois', 'NoOrdre', 'TitreRMC', 'AdopCSRegleVote', 'AdopCSAbs', 'AdoptCSContre', 'NoCELEX', 'ProposAnnee', 'ProposChrono', 'ProposOrigine', 'NoUniqueAnnee', 'NoUniqueType', 'NoUniqueChrono', 'PropoSplittee', 'Suite2LecturePE', 'Council PATH', 'Notes']
['1999', '1', '1', '1999/83/EC: Council Decision of 18 January 1999 authorising the Kingdom of Denmark to apply or to continue to apply reductions in, or exemptions from, excise duties on certain mineral oils used for specific purposes, in accordance with the procedure provided for in Article 8(4) of Directive 92/81/EEC', 'U', '', '', '31999D0083', '1998', '577', 'COM', 'NULL', 'CS', 'NULL', '', '', '', 'Propos* are missing on Celex document']
['1999', '1', '2', '1999/81/EC: Council Decision of 18 January 1999 authorising the Kingdom of Spain to apply a measure derogating from Articles 2 and 28a(1) of the Sixth Directive (77/388/EEC) on the harmonisation of the laws of the Member States relating to turnover taxes', 'U', '', '', '31999D0081', '1998', '184', 'COM', 'NULL', 'CS', 'NULL', '', '', '', 'Propos* are missing on Celex document']

It's also probably worth noting what version of python I'm using.

[9:20am][wlynch@watermelon /tmp] python -V
Python 2.7.2
2 of 6
14

Given a project that deals with both , (comma) and | (vertical bar) delimited CSV files, which are well formed, I tried the following (as given at https://docs.python.org/2/library/csv.html#csv.Sniffer):

dialect = csv.Sniffer().sniff(csvfile.read(1024), delimiters=',|')

However, on a |-delimited file, the "Could not determine delimiter" exception was returned. It seemed reasonable to speculate that the sniff heuristic might work best if each line has the same number of delimiters (not counting whatever might be enclosed in quotes). So, instead of reading the first 1024 bytes of the file, I tried reading the first two lines in their entirety:

temp_lines = csvfile.readline() + '\n' + csvfile.readline()
dialect = csv.Sniffer().sniff(temp_lines, delimiters=',|')

So far, this is working well for me.

🌐
GeeksforGeeks
geeksforgeeks.org › python › reading-and-writing-csv-files-in-python
Reading and Writing CSV Files in Python - GeeksforGeeks
July 15, 2025 - Explanation: The csv module reads Giants.csv using csv.reader(file), iterating row by row. The with statement ensures proper file closure. Each row is returned as a list of column values. Use next(csvFile) to skip the header. Python provides the csv.writer class to write data to a CSV file. It converts user data into delimited strings before writing them to a file.
🌐
Python Programming
pythonprogramming.net › reading-csv-files-python-3
Reading CSV files in Python
CSV literally stands for comma separated variable, where the comma is what is known as a "delimiter." While you can also just simply use Python's split() function, to separate lines and data within each line, the CSV module can also be used to make things easy.
🌐
AskPython
askpython.com › python-modules › pandas › read-csv-with-delimiters
Pandas read_csv() With Custom Delimiters - AskPython
January 31, 2022 - (Note: When recreating the above code, you need to mention the file path, as the file name can only be used when both the Python .txt file and the .csv file are present in the same directory). Let’s now learn how to use a custom delimiter with the read_csv() function.