Python 3.x 指定矩阵行错误

Python 3.x 指定矩阵行错误,python-3.x,input,Python 3.x,Input,我有一个矩阵,比如: 1 2 3 4 0 3 4 1 7 3 4 5 我想选择一行,然后用这一行做一些事情,比如用一些算法对它进行排序;到目前为止,我已经做到了: def row_management(matrix): theline = input('wich line?') #enter row number thelist = [matrix[theline]] #go take the right row of the matrix menu_thelist(th

我有一个矩阵,比如:

1 2 3 4
0 3 4 1
7 3 4 5
我想选择一行,然后用这一行做一些事情,比如用一些算法对它进行排序;到目前为止,我已经做到了:

def row_management(matrix):

   theline = input('wich line?') #enter row number
   thelist = [matrix[theline]]  #go take the right row of the matrix
   menu_thelist(thelist)  #supossed to use the row and take it to the list management menu
但是,当我运行此函数时,它总是返回一个错误“[matrix[theline]]TypeError:列表索引必须是整数,而不是str”,我不明白。调用返回一个
str
类型,因此它不能直接用作
matrix[theline]
中列表的索引,这也是错误消息所说的。相反,你应该:

matrix[int(theline)]

需要转换为int

theline = int(input('wich line?'))
而且

thelist = matrix[theline]
have[1,2,3]和not[1,2,3]](这会导致进一步的问题)