Update file2str.py

Sorry about my previous recommendation that broke Python 2. It's been so long that I forgot that Python 2 open 'rb' returns a string representation of bytes. The above code will properly handle type conversion for Python 2.
This commit is contained in:
Reed 2015-03-03 08:12:30 -08:00
parent 0fcb2b9ecb
commit 4b3a5f4f94

View File

@ -40,7 +40,10 @@ try:
chunk = src.read(16)
if chunk:
for b in chunk:
dst.write('0x%02x' % ord(b))
# For Python 2.x compatibility.
if isinstance(b, str):
b = ord(b)
dst.write('0x%02x' % b)
offs = offs + 1
if offs != byteCount:
dst.write(',')