calling source command within python

Glenn Hutchings zondo42 at googlemail.com
Fri Jul 25 19:13:10 CEST 2008


Jie <Jie.Bao at gmail.com> writes:
> i'm having trouble executing os.system('source .bashrc') command
> within python, it always says that source not found and stuff. Any
> clue?

There's no 'source' program; it's a shell builtin.  Even if there was, it
almost certainly wouldn't do what you want.  The .bashrc file is supposed
to contain settings applying to the current shell, and os.system() runs in
a subshell, so the settings will only affect that shell.

If you're doing this to set environment variables, try modifying os.environ
instead.

Glenn



More information about the Python-list mailing list