相关疑难解决方法(0)

TypeError:list indices必须是整数或切片,而不是str

我有两个列表,我想在一个数组中合并,最后把它放在一个csv文件中.我是Python的数组的新手,我不明白我怎么能避免这个错误:

def fill_csv(self, array_urls, array_dates, csv_file_path):
    result_array = []
    array_length = str(len(array_dates))

    # We fill the CSV file
    file = open(csv_file_path, "w")
    csv_file = csv.writer(file, delimiter=';', lineterminator='\n')

    # We merge the two arrays in one

    for i in array_length:
        result_array[i][0].append(array_urls[i])
        result_array[i][1].append(array_dates[i])
        i += 1

    csv_file.writerows(result_array)
Run Code Online (Sandbox Code Playgroud)

得到了:

  File "C:\Users\--\gcscan.py", line 63, in fill_csv
    result_array[i][0].append(array_urls[i])
TypeError: list indices must be integers or slices, not str
Run Code Online (Sandbox Code Playgroud)

我的计数如何运作?

python csv arrays list

37
推荐指数
3
解决办法
35万
查看次数

TypeError:list indices必须是整数,而不是str Python

list[s]是一个字符串.为什么这不起作用?

出现以下错误:

TypeError:list indices必须是整数,而不是str

list = ['abc', 'def']
map_list = []

for s in list:
  t = (list[s], 1)
  map_list.append(t)
Run Code Online (Sandbox Code Playgroud)

python mapreduce

11
推荐指数
3
解决办法
8万
查看次数

Python:TypeError:list indices必须是整数,而不是str

我要在Python上做Matrix Addition.(没有完成).但它显示错误.

m, n = (int(i) for i in raw_input().split())
a = [[0 for i in range(m)] for j in range(n)]
b = [[0 for i in range(m)] for j in range(n)]
c = []
total = []

for i in range(m):
    x = raw_input()
    for j in range(n):
        value = [int(i) for i in x.split()]
    c[i][j] = a[i][j]
    #c.append(value)
print a
for i in c:
    print i
Run Code Online (Sandbox Code Playgroud)

我想输入

3 3 < - 矩阵维m*n

1 2 3>

3 2 1>矩阵A. …

python matrix python-2.x typeerror

10
推荐指数
1
解决办法
5万
查看次数

标签 统计

python ×3

arrays ×1

csv ×1

list ×1

mapreduce ×1

matrix ×1

python-2.x ×1

typeerror ×1