0

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.

user123892
  • 1,243
  • 3
  • 21
  • 38
  • 1
    read this - https://stackoverflow.com/questions/6039605/typeerror-str-object-is-not-callable-python#14936426 – Sid Sep 16 '19 at 09:31

1 Answers1

2

You're missing a % sign. key = "%s%s" (key, carattere) needs to be changed into

key = "%s%s" % (key, carattere)
Teshan Shanuka J
  • 1,448
  • 2
  • 17
  • 31