AP_OSD: Simplify with the code enumerate()

* Avoid hardcoding the path to the python executable on the shebang line
* Using __with open() as__ automates file close().
This commit is contained in:
cclauss 2018-08-19 00:41:35 +02:00 committed by Andrew Tridgell
parent a7042e3847
commit 7291aa0d00

View File

@ -1,21 +1,17 @@
#!/usr/bin/python
import sys;
#!/usr/bin/env python
import sys
if len(sys.argv) < 3:
print "Usage: ./mcm2bin.py clarity.mcm clarity.bin"
print("Usage: ./mcm2bin.py clarity.mcm clarity.bin")
exit()
with open(sys.argv[1]) as inp:
content = inp.readlines()
inp.close();
content.pop(0)
out = open(sys.argv[2], 'wb')
i = -1
for line in content:
i = i + 1
if i % 64 < 54:
b = int(line, 2)
out.write(bytearray([b]))
out.close()
with open(sys.argv[2], 'wb') as out:
for i, line in enumerate(content):
if i % 64 < 54:
b = int(line, 2)
out.write(bytearray([b]))