I'd like to be able to run a python file (file1
) that simply loads several large files into memory as python objects, then, with a different python file (file2
), access those same objects without having to reload the files into memory a second time. The motivation is that I want to be able to iteratively modify/develop file2
without having to waste time reloading the same large files on every iteration.
In a Jupyter notebook this is easily accomplished by running a cell that loads the files once; these objects are then accessible to all other cells in the notebook. I'd like to be able to establish this same cross talk between separate python files.
Is there a way to establish the within-notebook Jupyter style cell-to-cell sharing of python objects between separate .py files?
(Edited to include an example)
Below is an example scenario; let's say there are two files:
file1.py
:
from sklearn.externals import joblib
q = joblib.load('large_dict') #load a large dictionary that has been saved to disk; let's say it takes 2 minutes to load
p = joblib.load('large_dict2') #load another large file; another 2 minutes load time
file2.py
:
#notice that the q, p objects are never loaded, but they are accessible
#(this is possible if the contents of these py files are in separate cells
#in a Jupyter notebook)
for experiment, chromosome in q.iteritems():
#stuff to work with dict object
for experiment, chromosome in p.iteritems():
#stuff to work with dict object
I want to do
python file1.py
once, and then do
python file2.py
an arbitrary number of times (i.e. iteratively modify the code in file2
). Notice that in this scenario the objects created in file1.py
are accessible to file2.py
. My question is: Is this scenario possible?