Pass variable between python scripts

前端 未结 5 1136
北恋
北恋 2020-12-02 18:37

I\'m sure this is very simple but I\'ve been unable to get it working correctly. I need to have my main python script call another python script and pass variables from the

5条回答
  •  没有蜡笔的小新
    2020-12-02 19:31

    Finally,

    I created a package for Python to solve this problem.


    Install Guli from PIP.

    $ pip install guli
    

    Guli doesn't require installing any additional PIP package.

    With the package you can

    Guli can be used to pass between different Python scripts, between many processes or at the same script. pass variables between main Process and another (Multiprocess) Process.

    • Pass variables between different Python scripts.
    • Pass variables between 'Main Process' and another (Multiprocess) Process.
    • Use variables at the same script.
    • Create / Delete / Edit - GuliVariables.

    Example

    import guli
    import multiprocessing
    
    string = guli.GuliVariable("hello").get()
    print(string) # returns empty string ""
    
    def my_function():
      ''' change the value from another process '''
      guli.GuliVariable("hello").setValue(4)
    
    multiprocessing.Process(target=my_function).start()
    
    import time
    time.sleep(0.01) # delay after process to catch the update
    
    
    string = guli.GuliVariable("hello").get()
    print(string) # returns "success!!!"
    

    Hope I solved the problem for many people!

提交回复
热议问题