Note that it supports Python 3

I started writing io_bit.py and io_midi.py in Python 2, so I took care of them for 3.

Related) http://d.hatena.ne.jp/yoya/20141106/io_midi

--Specify "b" to open the file as binary. (It works even if it is not 2)

X data = open(file).read()
O data = open(file,"rb").read()

――By the way, this is the error that appears in 3.

  File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/codecs.py", line 313, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe0 in position 13: invalid continuation byte

--Since the cut out data is also binary (byte string), add b like data == b "~" in the comparison check.

X   chunk == "MThd"
O   chunk == b"MThd"

--has_key cannot be used, so use in.

X a.has_key("x")
O "x" in a

--Rewrite cutting out 1 byte from a byte string to specify a range.

 X bytes [i] # ← In this case, the behavior is different between 2 and 3.
O bytes[i:i+1] 
$ python2 -c 'print(b"AB"[1])'
B
$ python3 -c 'print(b"AB"[1])'
66
$ python3 -c 'print(b"AB"[1:2])'
b'B'

--Fixed hard tab to soft tab. (2 works on hard tabs)

Recommended Posts

Note that it supports Python 3
Note: Python
Python note
Supports Python 2.4
Python study note_002
Note: Python Decorator
Python programming note
[Python] Learning Note 1
Python study note_004
Python study note_003
Note that Python decorators should have wraps
Technology that supports Python Descriptor edition #pyconjp
[Note] openCV + python
Python beginner's note
Note that Python decodes base64 format image and saves it locally
Note that Python list comprehensions are always confusing
Python: Create a class that supports unpacked assignment
[Note] File reading ~ Python ~
Note that I understand the least squares algorithm. And I wrote it in Python.
Note to daemonize python
Note: python Skeleton Nya
Python basic grammar note (4)
Python basic grammar note (3)
Python Tkinter Primer Note
Note that writing like this with ruby is writing like this with python
A simple Python HTTP server that supports Range Requests
Tool MALSS (basic) that supports machine learning in Python
AWS Lambda now supports Python so I tried it
MALSS, a tool that supports machine learning in Python
Python Input Note in AtCoder
[Note] Operate MongoDB with Python
[WIP] Fluent Python Study Note
Note links that may be useful when using Python, Selenium2
3 months note for starting Python
[AtCoder] ABC165C Personal Note [Python]
How to write a metaclass that supports both python2 and python3
A note about [python] __debug__
[Python] It seems that global variables cannot be referenced in Multiprocessing
[python] A note that started to understand the behavior of matplotlib.pyplot
What is Python? What is it used for?
Note that I understand the algorithm of the machine learning naive Bayes classifier. And I wrote it in Python.
Python Note: About comparison using is
That Python code has no classes ...
[Note] Project Euler in Python (Problem 1-22)
Python: A Note About Classes 1 "Abstract"
[python] Clock that changes color (animation)
(Note) Be careful with python argparse
[Note] Hello world output with python
This and that of python properties
boto3 (AWS SDK for Python) Note
Foreign Key in Python SQLite [Note]
A note that prints numpy.array nicely
Python Note: Get the current month
A note about mock (Python mock library)
[python] Script that (should) update pwsh
I made a Discord bot in Python that translates when it reacts
Note that Python dict returns default value if there is no key
A python program that resizes a video and turns it into an image
Find out the name of the method that called it from the method that is python
[Python] Note: A self-made function that finds the area of the normal distribution
Note that cibuildwheel builds python bwheel (including C ++ module) in bulk with CI and uploads it to PyPI