[Tutor] Linux variable to Python

Terry Carroll carroll at tjc.com
Tue May 17 09:27:20 CEST 2005


On Fri, 13 May 2005, Alberto Troiano wrote:

> 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 do something similar in a pure python program:


# get to temporary directory
(_year, _mon, _day, _hour, _min, _sec, _none, _none, _none)=time.localtime()
temp_dir = "D%4d-%02d-%02d-%02d%02d%02d" % (_year, _mon, _day, _hour, _min, _sec)
os.mkdir(temp_dir)
os.chdir(temp_dir)

This creates a directory in the form DYYYY-MM-DD-HHMMSS (for example, at 
6:10:08 PM on May 12, 2005, the directory is named D2005-05-12-181008), 
and then makes it the current directory.

You could probably do the same with minimal tweaking.



More information about the Tutor mailing list