我正在编写一个代码,其中我将一些文件存储到内存中的数据结构中,然后将在所有模块中使用该数据结构以访问该数据结构。 (节省时间)
由于代码是用 python 编写的,而且非常大,因此很难在函数之间传递该数据结构。
是否有任何可能的方法将文件到数据结构存储在代码的开头,然后我可以在任何模块中使用该数据结构,因为该数据结构在程序期间驻留在内存中执行。
请帮忙。非常重要..!!
我举个例子。
main.py ..... This is the start of the project, here I store the complete file-into-datastructure. other_module.py ..... This is some other module, where in i want to access that data structure which must be residing in the memory, as main.py is in execution and it had called other_module.py.
注意,我不能将文件到数据结构的东西存储在 other_module 中,因为那样会非常耗时,因为我在这里给出了一个非常小的例子,但实际上我正在处理一个更大的问题。
谢谢。
最佳答案
and is very big so its very hard to pass that data-structure from function-to-function.
不,不是。 Python 变量不是那样工作的。您隐含地获得了一个指针。
关于python - 如何将驻留在内存中的数据结构从一个模块传递到另一个模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10100399/