Create and read messagepacks in Python

sh



   sudo yum install python-pip -y

   sudo pip install msgpack-python msgpack-tool

test.csv: Space separated CSV file test.pack: Create a pack created as a floating point type

packer.py



import csv
import msgpack

infile = csv.reader(open('test.csv', 'rb'), delimiter=' ')
outfile = open('test.pack','w')
packer = msgpack.Packer()
for row in infile:
    outfile.write(packer.pack(map(float,row)))

Try piped with standard input and unpack the contents of the pack file

zcat test.pack.gz | unpacker.py

unpacker.py



import sys
import msgpack

BUF_SIZE = 64*1024
unpacker = msgpack.Unpacker()
while True:
    buf = sys.stdin.read(BUF_SIZE)
    if not buf:
        break
    unpacker.feed(buf)
    for obj in unpacker:
        print( obj )

Recommended Posts

Create and read messagepacks in Python
Read and write JSON files in Python
Read DXF in python
Create SpatiaLite in Python
Automatically create word and excel reports in python
Create a function in Python
Create a dictionary in Python
Create gif video in Python
Read Euler's formula in Python
Read Namespace-specified XML in Python
Stack and Queue in Python
Unittest and CI in Python
Read and write single precision floating point in Python
Read and write NFC tags in python using PaSoRi
Get stock prices and create candlestick charts in Python
MIDI packages in Python midi and pretty_midi
Difference between list () and [] in Python
Difference between == and is in python
View photos in Python and html
Sorting algorithm and implementation in Python
Create a DI Container in Python
Manipulate files and folders in Python
About dtypes in Python and Cython
Read and use Python files from Python
Read PNG chunks in Python (class)
Assignments and changes in Python objects
Create a binary file in Python
Tips for coding short and easy to read in Python
Create Gmail in Python without API
Preserve and read order in PyYAML
Ciphertext in Python: IND-CCA2 and RSA-OAEP
Hashing data in R and Python
Create code that outputs "A and pretending B" in python
Create Python project documentation in Sphinx
Function synthesis and application in Python
Read files in parallel with Python
Create a Kubernetes Operator in Python
Export and output files in Python
Reverse Hiragana and Katakana in Python2.7
Reading and writing text in Python
[GUI in Python] PyQt5-Menu and Toolbar-
Ignore # line and read in pandas
Create your own graph structure class and its drawing in python
Read big endian binary in Python and convert it to ndarray
Create a CGH for branching a laser in Python (laser and SLM required)
Overlapping regular expressions in Python and Java
Differences in authenticity between Python and JavaScript
Notes using cChardet and python3-chardet in Python 3.3.1.
Create your own Linux commands in Python
Differences between Ruby and Python in scope
AM modulation and demodulation in Python Part 2
difference between statements (statements) and expressions (expressions) in Python
Create ScriptableObject in Python when building ADX2
Eigenvalues and eigenvectors: Linear algebra in Python <7>
[LLDB] Create your own command in Python
Line graphs and scale lines in python
Create a simple GUI app in Python
Implement FIR filters in Python and C
Differences in syntax between Python and Java
Check and receive Serial port in Python (Port check)
Search and play YouTube videos in Python