简体   繁体   English

AttributeError: '_io.StringIO' object 没有属性 'StringIO'

[英]AttributeError: '_io.StringIO' object has no attribute 'StringIO'

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:我正在尝试实现 Lempel-Ziv-1978 数据压缩算法,我在解压 function 时遇到了该错误:

def decompresser(stringAdecompresser): def 解压器(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'我得到:文件“lz78.py”,第 52 行,在解压缩器中返回 resultat.StringIO() AttributeError: '_io.StringIO' object 没有属性 'StringIO'

Python version: 3.6 Python 版本:3.6

Your resultat is already a StringIO .您的resultat已经是StringIO Either return that, or, as @mechanical_meat suggests in his comment -- resultat.getvalue() .要么返回,要么正如@mechanical_meat 在他的评论中建议的那样—— resultat.getvalue resultat.getvalue()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM