Python Forum

Full Version: Import output from python script to another
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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.