-1

I have a python script with filename script.py with 2 functions:

def getname(name):
  print(name)

def setname(name, age, salary):
  print('Name: ' + name)
  print('age: ' + str(value))
  print('salary: ' + str(salary))

I want to access the function from a command line separately like this:

python script.py getname John Smith
>> John Smith

python script.py setname John Smith, 23, 5000
>> John Smith
   23
   5000
kulekhani
  • 1
  • 3
  • You have to evaluate the command-line arguments passed to the Python interpreter and then call the functions in the module accordingly. There are some libraries which make this easier. – mkrieger1 Jun 04 '22 at 10:05
  • Does this answer your question? [What packages are available for creating a Command Line Interface (CLI) in Python?](https://stackoverflow.com/questions/43550096/what-packages-are-available-for-creating-a-command-line-interface-cli-in-pytho) – mkrieger1 Jun 04 '22 at 10:05
  • What you want here is argument parsing. Have a look at this thread (not a duplicate, dont worry): https://stackoverflow.com/q/20063/8997916 and look at the argparse library. This is something I believe you can probably figure out yourself by knowing what to look for, but im sure someone will write an answer – DownloadPizza Jun 04 '22 at 10:05

0 Answers0