Python Glossary Русский

all Python 3Files & I/Oterm

csv.excel_tab

csv — dialects

A dialect for tab-separated (TSV) files in Excel style. It is registered as 'excel-tab' — with a hyphen, not an underscore.

Syntax

csv.reader(f, dialect='excel-tab')

The class name and the registered name differ: dialect='excel_tab' raises csv.Error 'unknown dialect'; use 'excel-tab' or the class csv.excel_tab itself. It differs from excel only in the delimiter: lines still end with '\r\n', and fields containing a tab are quoted.

Examples

import csv
import io
print(list(csv.reader(io.StringIO('a\tb\n'), dialect='excel-tab')))  # → [['a', 'b']]
try:
    csv.reader(io.StringIO(''), dialect='excel_tab')
except csv.Error as e:
    print(e)  # → unknown dialect

See also

Open in the full glossarydocs.python.orgReport an inaccuracy