call from pthon to shell

Jason Friedman jsf80238 at
Sun Feb 17 08:00:23 CET 2013

>>>> import os
>>>> os.system("i=3")
> 0
>>>> os.system("echo $i")
> 0
> why i can not get the value of i?

Each call to os.system starts a new shell.  Think about what would
happen if you opened a terminal and typed:

$ i=3

Then, close that terminal and open a new one.  You would not be surprised that

$ echo $i

returns nothing.

And, as mentioned by Andrew, even absent that problem os.system is not
the way to obtain the data you are looking for.

I realize this is now 5 days after you posted ... what were you
ultimately attempting to accomplish?

More information about the Python-list mailing list