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