all Python 3Files & I/Ofunction
csv.register_dialect()
csv — dialects
Registers a dialect under a string name so you can later pass just dialect='name' to reader and writer.
Syntax
csv.register_dialect(name, dialect='excel', **fmtparams)
The dialect registry is shared by the whole process: registering the same name again silently replaces the old dialect — even the built-in 'excel', after which dialect='excel' in other code means something else (reader and writer without dialect are not affected, but DictReader and DictWriter are: their default is the string dialect='excel'). Parameters can be passed without a class: register_dialect('semi', delimiter=';') takes the rest from excel. For a one-off tweak, just pass delimiter= to reader directly.
Examples
import csv
import io
csv.register_dialect('semi', delimiter=';')
print(list(csv.reader(io.StringIO('a;b;c\n'), 'semi'))) # → [['a', 'b', 'c']]
print('semi' in csv.list_dialects()) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy