python subprocess set shell var. and then run command - how?
Question: I need to do this:

    
    
    $ export PYRO_HMAC_KEY=123
    $ python -m Pyro4.naming
    

So, i found that the second one is possible to do with

    
    
    subprocess.Popen(['python','-m','Pyro4.naming'])
    

but how export shell variable before that?


Answer: To update the existing environment...

    
    
    import os, subprocess
    
    d = dict(os.environ)   # Make a copy of the current environment
    d['PYRO_HMAC_KEY'] = '123'
    subprocess.Popen(['python', '-m', 'Pyro4.naming'], env=d)
    

