0
我想追加到这是应该持有9或15个单词根据难易空grid_list
(无关的问题):试图追加空单
def list_function(): #creates the list that will be used for the grid from file_content_list
file_content_list = import_function()
grid_list = [[,,],[,,],[,,]] #this is the list used to make the grid
counter = 0 #defines counter which allows iteration
place = 0 #defines place which is what affects the place in grid_list that the word is added to
if counter < len(file_content_list): #counter decides how many times the next part loops
for word in file_content_list:
grid_list[0][place].append(word) #appends the current word to grid_list at the place of value of place
place += 1 #adds 1 to place
counter += 1 #adds 1 to counter
file_content_list.remove(word) #removes the used word
print grid_list
elif counter >= 3 and counter < 6: #if counter is equal to 4, 5 or 6
for word in file_content_list:
grid_list[0][place].append(word) #appends the current word to grid_list at the place of value of place
place += 1
counter += 1
file_content_list.remove(word)
print grid_list
else:
for word in file_content_list:
grid_list[0][place].append(word) #appends the current word to grid_list at the place of value of place
place += 1
counter += 1
file_content_list.remove(word)
print grid_list
return grid_list
这想出了错误:
AttributeError: 'str' object has no attribute 'append'
'grid_list [0] [place]'是一个字符串,应该是grid_list [0]或grid_list – ycy
再看看错误消息:''str'对象没有属性'append''。这意味着'grid_list [0] [place]'是一个'str'类型 –
'grid_list = [[,],[,,],[,,]]'应该在这个'AttributeError'之前产生'SyntaxError'甚至有机会出现。 – pzp