jepler at unpythonic.net
Thu Jun 13 19:42:59 CEST 2002
On Thu, Jun 13, 2002 at 07:19:48PM +0200, Thor wrote:
> Having this code
> print "source "+root+".in"
> os.system("source "+root+".in")
> the script does not run the root+".in" file, but copying and pasting the
> output form teh 1st line work.. what i'm doing wrong? Thanks in advance
It is not a Python problem. It is the difference between running
something in a shell or a subshell. The former is like typing
sh -c "source $ROOT.in"
the latter will not make any changes to the environment of the parent
shell. So setting environment variables, creating aliases, etc., won't
work like you'd hoped.
If you want to have a Python program that changes something in the
parent shell's environment, you have to arrange to execute it in the
shell. For instance,
source `python print_name_of_file_to_source.py`
eval `python print_shell_code_to_execute.py`
More information about the Python-list