Python reads the CSV file and reports an error
import csv with open('E:/Selenium2script/DDTModle/test.csv','rb') as f: readers = csv.reader(f) next(readers,None) for line in readers: print(line)
_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)
Problem analysis: This CSV file is a text file, not a binary file.
Solution:
import csv with open('E:/Selenium2script/DDTModle/test.csv','rt') as f: readers = csv.reader(f) next(readers,None) for line in readers: print(line)
Or we could replace rt with R.
Note: The next statement here does not read the header key value
with open(file_name,'wt',newline='') as f:
Add newline= “‘, the data written will not be blank.
Read More:
- No code, a solution to the error in the path of reading CSV file by Python: filenotfounderror: [errno 2] no such file or directory: ‘XX. CSV‘
- Pandas read the CSV file error filenotf oundError:File b ‘***.csv’ does not exist
- When reading the CSV file with Python 3, the Unicode decodeerror: ‘UTF-8’ codec can’t decode byte 0xd0 in position 0: invalid con appears
- Typeerror: write() argument must be STR, not bytes and the method of writing binary file in Python 3
- Typeerror: write() argument must be STR, not bytes and the method of writing binary file in Python 3
- HBase import CSV file
- Neo4j LOAD CSV Error: Query cannot conclude with LOAD CSV
- Python export data (CSV format)
- Python reads the configuration file. Ini and resolves the error
- Error in header file when calling OpenGL to open obj file in vs2013: unable to open include file: “GL / glut. H”: no such file or directories
- The solution to the error of importing CSV from Python to Python
- The conversion between [Python] bytes and hex strings.
- Django reads the txt file in view
- Fatal error C1010: unexpected end of file encountered while looking for precompiled header. Did you forget to add “ා include” StdAfx. H to the source
- When Python Django creates a database, can’t open file ‘ manage.py ‘: [Errno 2] No such file or directory
- C / C + + cannot open the source file directory, the header file is not imported, the solution is as follows
- Interesting undefined columns selected from read.table and read.csv
- Vue introduction path is correct, but it always reports an error: already included file name‘ ××ב differs from file name ‘ ××ב only in casing.
- Parsing the difference between “R” and “RB” patterns of text files (Python)
- Python how does a. Py file call classes and functions in another. Py file