0

I'm trying to adapt some files written in Jupyter Notebooks (via Anaconda) to get them running in the Mac OS Terminal without IPython functionality - but I'm having a hard time replacing the %store magic.

I had a Jupyter file connected to a websocket via asyncio that writes/updates a dictionary every 2 seconds and saves it using %store and I've got a version of that running in the Terminal as a .py file without %store.

I currently have multiple other Jupyter files all running in a loop via scheduler that read from that dictionary via %store -r but so far, I'm not able to reproduce this without %store -r.

Doing a search for "how to access variable/dictionary values from one python file in another" brings up import - but that just seems to bring in the initial empty/declared value of the dictionary rather than the latest continually updated one as it is when the websocket script is running.

While the new .py websocket file is running in the terminal I've tried various takes on:

import the_file

from the_file import the_function

from the_file import the_dictionary

...and regardless of whether I call the dictionary name or a function that returns the dictionary - they all give me the same initial empty dictionary.

Is there a way of having one .py file running and continually updating a dictionary or variable value and then continually getting that latest value (or dictionary, list, etc.) into another .py file without using IPython %store magic?

Thanks.

robobozo
  • 113
  • 1
  • 5
  • I think you are looking for [pickle](https://docs.python.org/3/library/pickle.html). [This post](https://stackoverflow.com/q/34342155/8508004) even refers to `%store` magic as 'lightweight pickle'. [`Dill`](https://github.com/uqfoundation/dill) which is highlighted in the top scoring answer in that last link, extends `pickle`. – Wayne Apr 26 '23 at 04:04

0 Answers0