[Tutor] Linux variable to Python

Alberto Troiano albertito_g at hotmail.com
Fri May 13 22:03:48 CEST 2005


Another problem

Here is an example of what I want to do:

I run over Linux shell the following command:

[root at siseg root]# fec=cam`date +%Y%m%d%H%M%S`.jpg
[root at siseg root]# echo $fec
[root at siseg root]# mv hola.txt grabacion/$fec

To explain for those who doesn't know:
The first line creates a variable named "fec" with the value cam(a Linux 
function returning year month day hour minute second).jpg
The second show the value of "fec"
The third moves hola.txt to the directory grabacion and puts the "fec" value 
as the new name for the file

I need to do this from Python but I'm having problems with the Linux 
I don't get any errors when I execute the commands
Here is what I'm doing

import os
>>>os.system("fec=cam`date +%Y%m%d%H%M%S`.jpg")
>>>os.system("echo $fec")
>>>os.system("mv hola.txt grabacion/$fec")

Then I check for the file and turns out that it moved hola.txt to grabacion 
with the same name
I think that for some extrange way it is not accepting the linux variable

I'm using Python 2.2.2 over Red Hat 9.0

Thanks in advanced


More information about the Tutor mailing list