I'm writing the following string in my output file:
bitstream.add("stri", 32)
where
def add(self, data, length):
s = ''
if (type(data) == str):
for char in data:
b = bin(ord(char))[2:]
s = s + "{:0>8}".format(b)
else:
s = bin(data)[2:]
if (len(s) < length):
resto = length - len(s)
for _ in range(0, resto):
s = '0' + s
s = s[0:length]
self.cache = self.cache + s
self.flush()
Later on I need to read the string from the output file. I use Python struct unpack
module as follows:
from struct import unpack
key_length_bytes = 32
key = ""
for _ in range(0, key_length_bytes):
carattere = chr(unpack('>B', in_file.read(1))[0])
key = "%s%s" (key, carattere)
I get
key = "%s%s" (key, carattere)
TypeError: 'str' object is not callable
Thank you for any help you could provide.