I am doing a Python scripting.
I have a string, the
print type(allInOne) # allInOne is my string
newFile = open("./all_in_one7.raw", "w")
allInOne = numpy.uint8(dataset.pixel_array).tostring()
allInOne = numpy.uint8(dataset.pixel_array).tostring() doesn't look like text. When writing anything but text to a file in Python, you need to open the file in binary mode (
"wb" instead of
"w") so that Python doesn't assume the
0x0A bytes are
'\n' line endings and attempt to convert them to the
'\r\n' line endings that are more common on Microsoft Windows.
To see if this is your problem, count that particular character:
print len(allInOne), "bytes" print len(allInOne) + allInOne.count('\n'), "bytes with 0A counted twice"