TypeError:列表索引必须是整数或切片,不能是Table



我试图在camelot的大pdf中提取一些表。这是工作,但现在我想提取每一个表从TableList重命名表每次。以下是我的代码摘录:

tables = camelot.read_pdf("file.pdf", pages = "1")
table = ""
for i in tables:
globals()['table'+str(i)] = tables[i] 

我有这个错误:

TypeError:列表索引必须是整数或片,而不是表

在这种情况下,我在第一页有两张表,在最后一期我有数百页和数十张表。

tables = camelot.read_pdf("file.pdf", pages = "1")
table = ""
for i in tables:
globals()['table'+str(i)] =i

试试这个。因为你的i现在是一个表对象。

如果你想要索引。

tables = camelot.read_pdf("file.pdf", pages = "1")
table = ""
for i in range(len(tables)):
globals()['table'+str(i)] =tables[i]