简体   繁体   中英

Reading a csv file with hexadecimal encoding

I am trying to read a csv file which apparently has hexadecimal encoding. The problem is that I don't get the numbers I am supposed to after reading the file, instead I get something strange like this:

PK!�S��N[Content_Types].xml �(����N�0E�H�C�-�ݲ@5���(`�Ib�/y���=��@�j7�b��s=3��6�k����ؘX��J��b������S�x�����f�����V�K)<  uV"�4>Z��7�"�z)[��у��K�R�z

instead of a normal number. Here is my code:

import csv
import binascii
import codecs

matrix = []
path = r'G:\maria data\Python\test.csv'
with open(path, errors="ignore") as f:
    reader = csv.reader(f)
    print(type(reader))
    j = 0
    reader = csv.reader(x.replace('\0', '') for x in f)
    for row in reader :
        matrix.append(row)
print(matrix[10][0])

When a ZIP file is viewed in a text editor the first two bytes of the file are usually "PK". Try to unzip it:

import zipfile
with zipfile.ZipFile(path_to_zip_file, 'r') as zip_ref:
    zip_ref.extractall(directory_to_extract_to)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM