Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Manipulating Binary Data
#11
Quote:My dictionary contains 1 key ('AA08') and then a list of all the data [data1, data2, data3 etc..] corresponding to that 1 key.

This way and it will keep the structure in and out of csv.
Can read it in with DictReader.
import csv

d = {'AA08': ['430022', '410234', '1111'], 'AB81': ['130138', '22222', '4444']}
with open("out.csv", "w") as out_file:   
    writer = csv.writer(out_file)
    writer.writerow(d.keys())
    writer.writerows(zip(*d.values()))
Output:
AA08, AB81 430022, 130138 410234, 22222 1111, 4444
Read it back.
>>> import csv
... with open('out.csv') as f:
...     reader = csv.DictReader(f)
...     for row in reader:
...         print(row['AA08'], row['AB81'])
430022 130138
410234 22222
1111 4444
Using Python 36 it will also return a OrderedDict.
As dictionary are ordered in 36.
>>> type(row)
<class 'collections.OrderedDict'>
>>> row
OrderedDict([('AA08', '1111'), ('AB81', '4444')])
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Reading Binary File, Missing Occurences Oliver 4 102 Jan-05-2018, 12:05 PM
Last Post: Oliver
  Converting an 8-bit binary to decimal WITHOUT the shortcuts EIA 5 150 Dec-01-2017, 09:04 AM
Last Post: stranac
  Denary to Binary game t0mhun13r 7 357 Nov-06-2017, 01:58 PM
Last Post: sparkz_alot
  Need Help: Sort of Binary numbers based on 1's present abinashj 5 384 Jul-25-2017, 12:23 PM
Last Post: buran
  Problem with serial data. How do I ignor incorrect data? donmerch 1 298 Jul-11-2017, 01:55 AM
Last Post: donmerch
  Need help reading in a binary file shaynehansen 2 476 Jun-22-2017, 10:04 AM
Last Post: zivoni
  binary data in source code form Skaperen 4 874 Jun-02-2017, 02:21 AM
Last Post: Skaperen
  HELP: String of Zero's and One's to binary byte schwasskin 0 434 Apr-07-2017, 03:04 AM
Last Post: schwasskin
  [?] UTF8, Unicode and Binary data reading troubles doublezero 1 424 Mar-31-2017, 11:32 PM
Last Post: Ofnuts
  binary trees Nucifera 3 556 Mar-10-2017, 08:07 AM
Last Post: Skaperen

Forum Jump:


Users browsing this thread: 1 Guest(s)