fwrite

Writing an ASCII string as binary in python

Writing an ASCII string as binary in python Question: I have a ASCII string = “abcdefghijk”. I want to write this to a binary file in binary format using python. I tried following: str = “abcdefghijk” fp = file(“test.bin”, “wb”) hexStr = “”.join( ((“\x%s”) % (x.encode(“hex”))) for x in str) fp.write(hexStr) fp.close() However, when I …

Total answers: 2