0

我有一个 CSV 文件,第一行是标题。

Header1 | Header2 | ... | HeaderN
Cell11  | Cell12  | ... | Cell1N
    .         .      .      .
    .         .      .      .
    .         .      .      .
CellM1  | CellM2  | ... | CellMN

我想将项目加载到本地内存中。因此,我使用命令 dict(zip(self.header, item)) 将项目加载为 dict 列表。然后该项目将如下所示:

[[{Header1: Cell11}, {Header2: Cell12}... {HeaderN: Cell1N}],
 [{Header1: Cell21}, {Header2: Cell22}... {HeaderN: Cell2N}],
                       ...
 [{HeaderM: CellM1}, {Header2: CellM2}... {HeaderN: CellMN}]]

标题是键,键值在单元格中。

由于搜索效率低,因此我想找到另一种方法将其存储在 ram 上。这样会引导我有效地找到这些项目。

将 CSV 文件加载到内置 sqlite3 中会更好吗?

提前致谢

4

1 回答 1

0

This question is probably what you're looking for:

How can I pass my locals and access the variables directly from another function?

...which talks about using locals.update().

Generally, manually changing locals is advised against (security reasons mainly), but it depends on what you are using the code for.

于 2013-09-06T09:37:16.653 回答