Is there a way for a python script to load and use environment modules? os.system(\'module load xxx\')
doesn\'t work since it executes them in a subshell (at le
Not directly, but here's one possible workaround, depending on your environment. Assuming you can preface your system command with ENVVAR=value
, you can do something along these lines:
import os
os.environ['EDITOR'] = 'vi'
cmd = "EDITOR=%(EDITOR)s $EDITOR" % os.environ
os.system(cmd)
The code assigns vi to your EDITOR environment variable, then passes it on the command line and runs the command, which (in this case) is EDITOR.