This is a demonstration of passing a variable from one python script to another, which usually is not really very simple, here we use the os shell as a mediator for passing the variable.
This script was created as a demonstration for the usage of os modules for passing variables between two different python scripts. Super General!
Tough the script was written and tested in python 3.8 release, the code is well commented and runs on almost any version of python, well don't go with 2.7 it's gone for good now.
The variable from the source.py
file is given out to the operating system shell as a commandline argument by running the destination.py
file with the variable as an argument, this variable is then accessed by the destination.py
file using argv list from the sys module.
- Simply run the
source.py
script from your command shell, that's it.
You can edit the variable that is being passed out as an argument in the
source.py
file Hasta la vista!
I will be dropping out more and more simple python scripts, the cummilative repo is planned to be called 'Super General', as a huge nadeking fan!
Contributions are very welcome! A lot of seasoned pythonistas would find these repos, very simple, but that's what these are meant to be Super General!
Find me on instagram @abhishekgidde