Sometimes it is not convenient to construct string using equal (=) like this:
str = "Hello, " ... str = str + "my name is " ... str = str + Name print str
In python, we have string stream (StringIO) that will behave like file stream, you can construct your string like this:
str=StringIO() ... str.write("Hello, ") ... str.write("my name is ") ... str.write(Name) print str.getvalue()
The same way, you can construct your binary bytes with StringIO and write it into file once you are done.
bin=StringIO() bin.write("/x5F/x5F%c" % 0xFF) ... file = open ("my.bin","wb") file.write(bin.getvalue()) file.close()