Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Process mixed bytes data into python list

I am reading data remote .dat files for EDI data processing.

Original Data is some string bytes:

b'MDA1MDtWMjAxOS44LjAuMDtWMjAxOS44LjAuMDsyMDIwMD.........'

Used decode as below…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

byte_data = base64.b64decode(byte_data)

Gave me this below byte data. Is there a better way to process below bytes data into python list ?

b"0050;V2019.8.0.0;V2019.8.0.0;20200407;184821\r\n0070;;7;0;7\r\n0080;11;50;bot.pdf;Driss;C:\\Dat\\Abl\\\r\n0090;1;Z;Zub\xf6r;0;0;0;Zub\xf6r;;;Zub\xf6r\r\n

Tried decode with uft-8, didn’t work.

byte_data.decode('utf-8')

Tired to convert to string and read as CSV but did not help, landed on original data. Need to keep some of the string as it is and convert \xf6r \r \n

data = io.StringIO(above_data)
data.seek(0)
csv_reader = csv.reader(data, delimiter=";")

>Solution :

It didn’t work with ‘utf-8’ because it’s not ‘utf-8’, it’s probably ‘ISO-8859-1’ (latin-1)

text = byte_data.decode('ISO-8859-1')

because \xf6 is ö in ‘ISO-8859-1’

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading