Feature or enhancement
There is no easy way to get a CSV dialect that differs from an existing one in a single formatting parameter. You either repeat all parameters in a csv.Dialect subclass, or pass the individual parameters to csv.reader()/csv.writer() at every call site.
I propose to support copy.replace() for dialects — both instances of csv.Dialect subclasses and the dialect objects returned by csv.get_dialect().
>>> dialect = copy.replace(csv.get_dialect('excel'), delimiter=';', strict=True)
>>> list(csv.reader(['a;b'], dialect))
[['a', 'b']]
Parameters that are not replaced are inherited from the original dialect, and the result is validated like a newly created dialect.
Note that some parameters depend on each other and may need to be replaced together. For example, replacing quotechar with None also requires replacing quoting with QUOTE_NONE, otherwise validation fails with "quotechar must be set if quoting enabled".
Linked PRs
Feature or enhancement
There is no easy way to get a CSV dialect that differs from an existing one in a single formatting parameter. You either repeat all parameters in a
csv.Dialectsubclass, or pass the individual parameters tocsv.reader()/csv.writer()at every call site.I propose to support
copy.replace()for dialects — both instances ofcsv.Dialectsubclasses and the dialect objects returned bycsv.get_dialect().Parameters that are not replaced are inherited from the original dialect, and the result is validated like a newly created dialect.
Note that some parameters depend on each other and may need to be replaced together. For example, replacing
quotecharwithNonealso requires replacingquotingwithQUOTE_NONE, otherwise validation fails with "quotechar must be set if quoting enabled".Linked PRs