As already indicated in comments, the argument to os.system
is just a string; so you'd use Python's regular string formatting features to create it.
import os
urlpath = input('Enter the URL')
filename = input('Enter the filename with extension')
os.system("svn export '{0}/{1}'".format(urlpath, filename))
However, you probably should prefer subprocess.run
as strongly hinted in the os.system
documentation.
import subprocess
urlpath = input('Enter the URL')
filename = input('Enter the filename with extension')
subprocess.run(['svn', 'export', urlpath+'/'+filename],
check=True)
With check=True
you get an explicit error if the command fails (os.system
will only let you know through the exit status, which you were not examining) and because we don't use shell=True
, this should be a tiny bit faster. Notice also how the first argument is a list of tokens, not a string which the shell has to pick apart again (remember, there is no shell here now).
subprocess.run()
was introduced in Python 3.5; if you need to support older versions, maybe explore replacing it with subprocess.check_call()
A much better design would get rid of the interactive input
calls and allow the user to pass in parameters as command-line arguments (sys.argv
); that way, you get to use the shell's history and file name completion features so you don't need to type file names in full by hand, and can easily recall files you have recently used. This also makes it feasible to build additional automation around your script, because then programs can easily drive other programs.
import sys
import subprocess
import logging
if len(sys.argv) != 3:
logging.error('syntax: {0} baseurl filename'.format(
sys.argv[0].split('/')[-1}))
sys.exit(2)
urlpath = sys.argv[1]
filename = sys.argv[2]
subprocess.run(['svn', 'export', urlpath+'/'+filename],
check=True)