String variables in python function? -


i'm writing script in python, not able use multiple stings in cases check directory, file creation etc,

i'm using user input : drive = raw_input('enter drive name make backup ')

if not os.path.exists('/media/%s/backup' %drive):     os.mkdir('/media/%s/backup' %drive) 

the above code working, tarfile below giving error........

./backup4.py  enter drive name make backup pendrive traceback (most recent call last):   file "./backup4.py", line 17, in <module>     tarfile = tarfile.open("/media/%s/backup/%s.tar.bz2" %drive %datevar, 'w:bz2') typeerror: not enough arguments format string   tarfile = tarfile.open("/media/%s/backup/%s.tar.bz2" %drive %datevar, 'w:bz2') 

what changes should make above tarfile.open??

your string formatting incorrect. need pass tuple of variables equal amount of substitutions in string.

tarfile = tarfile.open("/media/%s/backup/%s.tar.bz2" % (drive, datevar), 'w:bz2') 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -