I am learning python and i am trying to write a stupid code and got stuck here, I am need backupfile name like full-backup-ucs-2013-02-12
#!/usr/bin/python
import os
from time import strftime
DATE=`strftime("%Y-%m-%d")`
backupfile = "full-backup-ucs-" + DATE
print backupfile
When i run i got following output, did you see it print two single quote ' ' in date, I want to remove them. I am sure there is elegant way to do that please suggest:
[spatel@tux work]$ ./backup.py
full-backup-ucs-'2013-02-12'
You can use the
datetimemodule to get this information.As I’m sure you’ve noticed, backtic substitution doesn’t work in python as it does in the shell. It implicitly calls
repr(in python2.x) which is where your additional quotes are coming from.EDIT — Apparently you could just use remove the backtics and your code should more or less work as
time.strftimeuses the current localtime if you omit the second argument.