A line of content read by CSV contains a null byte
which in Python is \x00
In [1]: a = '\0'
In [2]: a
Out[2]: '\x00'
In [3]: b = '\x00'
In [4]: b
Out[4]: '\x00'
In [5]: a == b
Out[5]: True
Make an error file like this, print it out in PyCharm, and then copy the printed result to a CSV file
print('1,\x00,2')
OK, the exception file has the
test code
with open('file.csv', 'r') as f:
reader = csv.reader(f)
next(reader)
Error: line contains NULL byte
. So, how do you do that
Modify the code
with open('file.csv', 'r') as f:
reader = csv.reader(_.replace('\x00', '') for _ in f)
next(reader)
Why this terrible mistake?
1. The data in it has this thing
2. The file is an excel file, but the result is saved as CSV
3. Multiple processes read and write to the same file
Read More:
- Unicode decodeerror: ‘UTF-8’ codec can’t decode byte 0x80 in position 3131: invalid start byte solution
- Cause: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 26; Byte 1 of 1-byte UTF-8 sequence is invalid.
- Solution of Unicode decodeerror -‘utf-8 ‘codec can’t decode byte 0xc4 in position 0 – invalid continuation byte
- UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xd6 in position 3089: invalid continuation byte
- UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xc3 in position 54: invalid continuation byte
- Solve the ‘UTF-8’ codec can’t decode byte 0xe9 in position 3114: invalid continuation byte error
- SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
- org.apache.ibatis.type.TypeException: Error setting non null for parameter #4 with JdbcType null
- Java 8 Stream – Read a file line by line
- Error:null value in entry: incrementalFolder=null
- The language of C__ FILE__ 、__ LINE__ And line
- Three ways of single line and multi line comment in Python
- ERROR: invalid byte sequence for encoding “UTF8”: 0x00
- Command line is too long. Shorten command line for QuestionnaireApplication or also for Spring Boot
- [Solved] error: cannot create �� Illegal byte sequence
- JSON parse e rror: Invalid UTF-8 middle byte 0x3f;
- Unicode decodeerror: ‘UTF-8’ codec can’t decode byte 0xd3 in position 238: invalid continuation B
- Let’s get started with latex 05, line feed, paragraph feed, page feed, first line indent, etc
- Successfully resolved Unicode decodeerror: ‘UTF-8’ codec can’t decode byte 0xd3 in position 238: invalid continuation B