MCPcopy Index your code
hub / github.com/python/cpython / read_table

Function read_table

Tools/c-analyzer/c_common/tables.py:84–116  ·  view source on GitHub ↗

Yield each row of the given ???-separated (e.g. tab) file.

(infile, header, *,
               sep='\t',
               fix=None,
               _open=open,
               _get_reader=csv.reader,
               )

Source from the content-addressed store, hash-verified

82
83
84def read_table(infile, header, *,
85 sep='\t',
86 fix=None,
87 _open=open,
88 _get_reader=csv.reader,
89 ):
90 """Yield each row of the given ???-separated (e.g. tab) file."""
91 if isinstance(infile, str):
92 with _open(infile, newline='') as infile:
93 yield from read_table(
94 infile,
95 header,
96 sep=sep,
97 fix=fix,
98 _open=_open,
99 _get_reader=_get_reader,
100 )
101 return
102 lines = strutil._iter_significant_lines(infile)
103
104 # Validate the header.
105 if not isinstance(header, str):
106 header = sep.join(header)
107 try:
108 actualheader = next(lines).strip()
109 except StopIteration:
110 actualheader = ''
111 if actualheader != header:
112 raise ValueError(f'bad header {actualheader!r}')
113
114 fix_row = _normalize_fix_read(fix)
115 for row in _get_reader(lines, delimiter=sep or '\t'):
116 yield tuple(fix_row(row))
117
118
119def write_table(outfile, header, rows, *,

Callers

nothing calls this directly

Calls 4

_normalize_fix_readFunction · 0.85
fix_rowFunction · 0.85
joinMethod · 0.45
stripMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…