Я пытался добавить символ к элементу в списке, но он не работает.
Я пробовал следующие строки кода:
listofobjects[i].append(char)
и
listofobjects[i] = list[i] + char
и
listofobjects[i] = str(list[i]) + char
в этом коде:
file_enter = open("LogoRLE.txt","r")
#reads line
l = file_enter.readline()
#string where compressed data is stored
compdata = ''
#string where uncompressed data will be stored
uncompdata = ''
#count is used so decompression can stop once the file has been read
count = 0
#counts for every three characters
charcount = 0
#listno is used to add decompressed characters to a specific element
listno = 0
#where all uncompressed data will stored
uncompdatal = []
while charcount != len(file_enter.read()):
for i in str(l):
count += 1
charcount += 1
compdata = compdata + i
print (compdata)
if count == 3:
number = int(compdata[:2])
char = compdata[2:]
compdata = char*number
uncompdata = uncompdata + compdata
uncompdatal.append(uncompdata)
uncompdatal[listno] = str(uncompdatal[listno]) + uncompdata
print(uncompdatal)
#resets values for next three characters
compdata = ''
uncompdata = ''
count = 0
print(charcount)
#display(uncompdatal)
l = file_enter.readline()
print(l)
listno += 1
Я читаю символы из текстового файла.Я читаю строку, сохраняю ее как строку и разделяю каждые 3 символа, так как она сжата RLE, и я пытаюсь распаковать.
Пример 3 символов:
01f04g02,
После распаковкипервые три символа строки, я добавил его в список и хочу добавить другие распакованные символы в один элемент для одной распакованной строки.
Я хочу, чтобы он вывел этот результат:
["fgggg,,"]
Он не работает, поскольку есть выход, но его невозможно увидеть, поскольку оболочка продолжает работать и ничего не показывает.