Just use the csv module. It knows about all the possible corner cases in CSV files like new lines in quoted fields. And it can delimit on tabs.
with open("file.tsv") as fd: rd = csv.reader(fd, delimiter="\t", quotechar='"') for row in rd: print(row)
will correctly output:
['111', '222', '333', 'aaa'] ['444', '555', '666', 'bb\nb']
Related Posts:
- Python Pandas Error tokenizing data
- python csv2libsvm.py: AttributeError: ‘_csv.reader’ object has no attribute ‘next’
- TypeError: list indices must be integers or slices, not str
- IndexError: too many indices for array
- IndexError: too many indices for array
- Writing a pandas DataFrame to CSV file
- Writing a pandas DataFrame to CSV file
- IndexError: too many indices for array
- ValueError : I/O operation on closed file
- Pandas: ValueError: cannot convert float NaN to integer
- csv.Error: iterator should return strings, not bytes
- Python – Reading and writing csv files with utf-8 encoding
- Python Error io.UnsupportedOperation: not readable
- load csv into 2D matrix with numpy for plotting
- Dump a NumPy array into a csv file
- (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
- Is there a way to include commas in CSV columns without breaking the formatting?
- How to load a tsv file into a Pandas DataFrame?
- Difference between writerow() and writerows() methods of Python csv module
- Create a .csv file with values from a Python list
- Convert XML to CSV file
- TypeError: list indices must be integers or slices, not str
- Convert from CSV to array in Python
- ValueError: cannot index with vector containing NA / NaN values
- (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
- Creating a dictionary from a csv file?
- Python import csv to list
- ValueError: x and y must be the same size
- OSError: Initializing from file failed on csv in Pandas
- append new row to old csv file python
- “extra data after last expected column” while trying to import a csv file into postgresql
- Writing a dictionary to a csv file with one line for every ‘key: value’
- Python CSV error: line contains NULL byte
- In Java, what is the “char” for a tab and how do I pass through a “Charset”?
- Python CSV Error: sequence expected
- AttributeError: ‘float’ object has no attribute ‘split’4
- How to add pandas data to an existing csv file?
- convert csv file to list of dictionaries
- _csv.Error: field larger than field limit (131072)
- CSV new-line character seen in unquoted field error
- Writing Python lists to columns in csv
- Error in Reading a csv file in pandas[CParserError: Error tokenizing data. C error: Buffer overflow caught – possible malformed input file.]
- How to read a CSV file from a URL with Python?
- How to import a csv-file into a data array?
- WordPress.com Stats stats_get_csv with custom field?
- How to import .csv file with descriptions to a gallery in media?
- Updating Custom Posts via CSV Import
- CSV import stopped working when I upgraded to WP 3.5.2
- How to add to the PYTHONPATH in Windows, so it finds my modules/packages?
- FileNotFoundError: [WinError 2] The system cannot find the file specified:
- Remove all whitespace in a string
- What is a “method” in Python?
- How to generate all permutations of a list?
- Is there a Python equivalent to Ruby’s string interpolation?
- Python Progress Bar
- Most efficient way to find mode in numpy array
- Python error “ImportError: No module named”
- How to groupby based on two columns in pandas?
- Creating a basic auto clicker in python
- What’s the difference between torch.stack() and torch.cat() functions?
- How to print to stderr in Python?
- proper name for python * operator?
- How to do superscripts and subscripts in Jupyter Notebook?
- How do I unload (reload) a Python module?
- How to exit a loop in Python?
- What does axis in pandas mean?
- What do >> and << mean in Python?
- How to parse a CSV file using PHP
- Dynamically growing a python array when assigning to it
- “OverflowError: Python int too large to convert to C long” on windows but not mac
- Can’t compare naive and aware datetime.now() <= challenge.datetime_end
- List of zeros in python
- How to remove an element from a list by index
- How to add title to subplots in Matplotlib
- ‘pip3’ is not recognized as an internal or external command, operable program or batch file
- Apply function to each element of a list
- print variable and a string in python
- can’t remove python pip
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- ValueError: unsupported pickle protocol: 3, python2 pickle can not load the file dumped by python 3 pickle?
- Relative paths in Python
- Convert bytes to int?
- SQLAlchemy ORDER BY DESCENDING?
- ValueError: unsupported pickle protocol: 3, python2 pickle can not load the file dumped by python 3 pickle?
- Relative paths in Python
- AttributeError(“‘str’ object has no attribute ‘read'”)
- Python: count repeated elements in the list
- Is there a “do … until” in Python?
- Printing variables in Python 3.4
- Histogram plotting “AttributeError: max must be larger than min in range parameter.”
- Python TypeError: non-empty format string passed to object.__format__
- AttributeError: ‘Series’ object has no attribute ‘reshape’
- Repeated “Kernel died, restarting” forever
- How to clear Tkinter Canvas?
- Python official installer missing python27.dll
- TypeError: ‘range’ object does not support item assignment
- Convert string to variable name in python
- Python-like list comprehension in Java
- Syntax highlighting in vim for python
- How to fetch csv file and show in shortcode