On Tue, Jul 08, 2014 at 03:45:42PM -0500, Jim Byrnes wrote:
> I would like to automate running virtualenv with a python script by:
> 
> opening gnome-terminal
> cd to proper directory
> run source /bin/activate

Why not just run /bin/activate directly from Python?

os.chdir("the/proper/directory")
os.system("/bin/activate")

> I found some examples of using os.system() to get gnome-terminal to open 
> but I can't figure out how then cd to the proper directory in the new 
> terminal.
> 
> My biggest frustration right now is that I can't find any documentation 
> on how to use os.system().  Looking at the docs on the Python site I 
> don't see system() under the os module.  Googling hasn't helped.

https://docs.python.org/2/library/os.html#os.system

I found it by going to the os module, then using my browser's Find In 
This Page (not google!) function to look for "os.system", then clicking 
the very first link that came up.

Basically, if you can type a command at the shell prompt, you can run 
the same thing using os.system. There are a few complications due to the 
fact that each call to os.system operates in isolation from any other 
call to os.system e.g. this won't touch the file /tmp/foo:

os.system("cd /tmp")
os.system("touch foo")

but this will:

os.system("cd /tmp; touch foo")

but otherwise it is as simple as it gets.



-- 
Steven
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to