[Tutor] Linux variable to Python
Lee Harr
missive at hotmail.com
Fri May 13 22:48:41 CEST 2005
>import os
>>>>os.system("fec=cam`date +%Y%m%d%H%M%S`.jpg")
>0
>>>>os.system("echo $fec")
>0
>>>>os.system("mv hola.txt grabacion/$fec")
>0
Each system() call gets a fresh shell, and a fresh env ...
>>>import os
>>>os.environ['foo'] = 'bar'
>>>os.system('echo $foo')
bar
0
>>>os.system('foo=zzz')
0
>>>os.system('echo $foo')
bar
0
>>>os.system('export foo=zzz')
0
>>>os.system('echo $foo')
bar
0
>>>os.environ['foo']
'bar'
If you really need to work with environment variables
use os.environ, but I have a feeling you do not really
need that and it's going to be messy.
How about this ...
import datetime
timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
filename = 'cam%s.jpg' % timestamp
os.rename('hola.txt', filename)
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
More information about the Tutor
mailing list