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
  Need help reading in a binary file shaynehansen 2 78 Jun-22-2017, 10:04 AM
Last Post: zivoni
  binary data in source code form Skaperen 4 172 Jun-02-2017, 02:21 AM
Last Post: Skaperen
  HELP: String of Zero's and One's to binary byte schwasskin 0 196 Apr-07-2017, 03:04 AM
Last Post: schwasskin
  [?] UTF8, Unicode and Binary data reading troubles doublezero 1 163 Mar-31-2017, 11:32 PM
Last Post: Ofnuts
  binary trees Nucifera 3 267 Mar-10-2017, 08:07 AM
Last Post: Skaperen
  Find offset of binary data in file sparkz_alot 3 315 Mar-01-2017, 10:30 PM
Last Post: Larz60+
  Manipulating files Python 2.7 hugobaur 6 770 Nov-01-2016, 12:28 PM
Last Post: hugobaur

Forum Jump:


Users browsing this thread: 1 Guest(s)