Python Forum
Import output from python script to another - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Import output from python script to another (/thread-30235.html)



Import output from python script to another - varietyjones - Oct-12-2020

Hello
I want to find a solution which make me do the whole idea below:
I want to import an output of my python script in another python script file(i have 2 python files )
The first one :File 1. py contains an output string that auto change after a while..

out1 = 'function' ( the values change after some time)
i want to import the out1 in the other file (File2. py)..and get the values after any change from the file1. Py
how may i solve this i tried with loops but nothing. Thanks


RE: Import output from python script to another - bowlofred - Oct-12-2020

In my programs, I wouldn't want to use import this way.  It's too easy to bring in unexpected things.  Simpler I would think would be to put the information in a container (list or dict) and then put that into a file (perhaps via JSON formatting).  Then you can read it in whenever you want into a variable that you control.

But if you do want to use import, it will normally only attempt read it once per program invocation.  Take a look at importlib.reload to re-import a previously imported module.