good way to avoid recomputations?
Erik
python at lucidity.plus.com
Tue Apr 5 17:02:42 EDT 2016
Hi Maurice,
On 05/04/16 21:54, Maurice wrote:
> Hi. I working on a project where I have 5 scripts loading the same
> file at the very beginning so I would like to know the best way I can
> get this file without having to compute it 5 times.
>
> I also perform, in all the scripts, a list comprehension using this
> file that takes 30s to run. Would be cool to always have access to it
> as well.
It sort of depends on what data you are extracting from the file (so
expect people to ask for more information), but my initial gut reaction
is to suggest writing a class that ingests the file.
Create an object of that class, giving it the filename to ingest, and
then use it in each of the 5 places.
Or .... are you saying that each script is entirely separate? If so,
then one approach might be to write a single script that "loads" the
file and runs the comprehension and then "pickle" (look it up in the
docs) the resulting structure. Your other scripts can then load the
pickled version of the pre-computed comprehension much faster.
E.
More information about the Python-list
mailing list