0

I am new to python and trying to pass the three variables in to the python script with the below command line..!

$ python C:\test.py --var_name1=cityname --ds_name2="state.sas7bdat" --path="C:\"

Below is the script that I use..

import re
import sys
args = {}
args['pythonFile'] =  sys.argv[0]
for arg in sys.argv[1:]:
  variable = re.search('\-\-(.*)\=',arg)
  variable = variable.group(1)
  value = re.search('\=(.*)',arg)
  value = value.group(1)
  args[variable] = value
print(args)

args prints

{'pythonFile': 'C:\test.py', 'var_name1'='cityname', 'ds_name2'='state.sas7bdat', 'path'='C:\'

Now, how would like to use var_vame1, ds_name, path variables in the python script? for example.. I want to use..

filename=<PATH><DS_NAME>

how do I call these variables in the script? Appreciate your help.

BTables
  • 4,413
  • 2
  • 11
  • 30
prad001
  • 1
  • 2
  • 1
    Try to use argpase modul, it makes this task lot easier – Christoph Nov 04 '21 at 19:10
  • 1
    Does this answer your question? [How to read/process command line arguments?](https://stackoverflow.com/questions/1009860/how-to-read-process-command-line-arguments) – buran Nov 04 '21 at 19:10

0 Answers0