Browse Source
* Avoid hardcoding the path to the python executable on the shebang line * Using __with open() as__ automates file close().mission-4.1.18
cclauss
7 years ago
committed by
Andrew Tridgell
1 changed files with 8 additions and 12 deletions
@ -1,21 +1,17 @@
@@ -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])) |
||||
|
Loading…
Reference in new issue