[Tutor] interacting with shell

Andrei Kulakov ak@silmarill.org
Fri, 19 Apr 2002 14:34:05 -0400


On Thu, Apr 18, 2002 at 06:42:46PM -0400, Paul Tremblay wrote:
> I am wondering how (of if) you interact with shell commands in
> python. For example, in perl you can assign a variable to the
> output from a command line. (I am using linux.)
> 
> $date = `date`
> 
> The string between the backslashes gets passed to the shell.
> 
> In python, I see you can use the command
> 
> os.system('date')
> 
> But can you assign this to a variable? 
> 
> Here is another example. I have written a small script in perl to
> backup my files. I use perl code to determine what type of backup
> I want to do, and store this value in the $backup variable. I
> can then pass this to the shell with a command like this. 
> 
> `find /bin -ctime -$backup \! -type d`
> 
> Perl knows to change the variable $backup to the value stored in
> it and then passes it to the shell.
>
os.popen("find /bin -ctime -%s \! -type d" % backup)
# %s gets replaces with value of backup variable

> 
> I am hoping you can do this in python. If not, then I can see
> where I would be somewhat limited in python.
> 
> Thanks!
> 
> Paul
> 
> -- 
> 
> ************************
> *Paul Tremblay         *
> *phthenry@earthlink.net*
> ************************
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org