mirror of
https://github.com/opentx/opentx.git
synced 2025-07-19 22:35:12 +03:00
Instead of manually opening and closes file objects, use the context manager that will properly handle opening and closing files for us, even in the event of some error
20 lines
436 B
Python
Executable file
20 lines
436 B
Python
Executable file
#!/usr/bin/env python
|
|
|
|
from __future__ import division
|
|
import sys
|
|
|
|
filename = sys.argv[1]
|
|
fileout = sys.argv[2]
|
|
|
|
# Read entire file
|
|
with open(filename, "rb") as fr:
|
|
sts = fr.read()
|
|
# Parse into chunks of 16 bytes
|
|
sts = [sts[i * 16:(i + 1) * 16] for i in range(len(sts) // 16)]
|
|
|
|
with open(fileout, "w") as fw:
|
|
for st in sts:
|
|
for b in st:
|
|
fw.write("0x%02x," % ord(b))
|
|
fw.write("\n")
|
|
fw.write("\n")
|