Python: assign to sys.argv item, and use it further
Question: Script 'top.py' makes use of another script 'myScript.py' by passing an
argument to it. Script 'myScript.py' contains:

    
    
    if __name__ == "__main__":
        ...
        sys.argv[1] = myObject
        sys.argv[1].functionSpecificToMyObject() # works as expected
    

The use is achieved in 'top.py' by simply calling 'myScript.py' with an
argument 'myHelperArgument'. However, in top.py I cannot make use
'myHelperArgument'. Is this possible? If not, any suggestion on a possible
solution (given the intention above) is welcome. Of course, I prefer not to
write to a file and read later.


Answer: I would recommend [import](https://docs.python.org/3/reference/import.html).
This is designed to use objects defined in one Python source file (module) in
another.

Create two files in the same directory:

First file `my_lib.py`:

    
    
    def my_func():
         return 42
    

Second file `my_script.py`:

    
    
    import my_lib
    
    print(my_lib.my_func())
    

Now, `python my_script.py` in the same directory shows `42`.

