Is there any way to access variable like $var (similar to shell scripting) in python? -
hi i'm new python programming.
i want copy file source destination. i'm using shutil.copy2(src,dst). in src , dst path , want use variable.
for example (variable name): pkg_name = xyz_1000 src path : /home/data/$pkg_name/file.zip
in shell can use $pkg_name access variable, there similar way in python?
main concern , if want use variable(s) in copy command , how can achieve in python ? in advance.
pkg_name = xyz_1000 using format()
src_path = "/home/data/{pkg_name}/file.zip".format(pkg_name=pkg_name) or
src_path = "/home/data/%s/file.zip" % pkg_name or
src_path = "/home/data/" + pkg_name + "/file.zip" or
src_path = string.template("/home/data/$pkg_name/file.zip").substitute(locals()) # or maybe globals() instead of locals(), depending on pkg_name defined.
Comments
Post a Comment