0
votes

I am looking for the solution to this error and I checked other similar questions but couldn't find an answer. I am trying to implement Lempel-Ziv-1978 data compression algorithm and I have that error in my decompression function which is:

def decompresser(stringAdecompresser):

from io import StringIO

# creer la dictionnaire
size = 256
dictionnaire = {chr(i): i for i in range(size)}

resultat = StringIO()
w = chr(stringAdecompresser.pop(0))
resultat.write(w)
for k in stringAdecompresser:
    if k in dictionnaire:
        entree = dictionnaire[k]
    else: # k == size:
        entree = w + w[0]


    resultat.write(entree)

    #ajouter dans la dictionnaire
    dictionnaire[size] = w + entree[0]
    size += 1

    w = entree
return resultat.StringIO()

and I got: File "lz78.py", line 52, in decompresser return resultat.StringIO() AttributeError: '_io.StringIO' object has no attribute 'StringIO'

Python version: 3.6

1
I think you want: return resultat.getvalue()... - mechanical_meat

1 Answers

0
votes

Your resultat is already a StringIO. Either return that, or, as @mechanical_meat suggests in his comment -- resultat.getvalue().