-2

How can I send the bellow to function parameters?

Example

[superuser@superuser deneme]$ myprogram.py --name=Jhon --surname=Wick --day=1  

How can I do as I stated? Thanks for your help

pradeexsu
  • 1,029
  • 1
  • 10
  • 27
  • You can use [argparse](https://docs.python.org/3/library/argparse.html) – atin Dec 27 '20 at 12:36
  • Does this answer your question? [How to read/process command line arguments?](https://stackoverflow.com/questions/1009860/how-to-read-process-command-line-arguments) – Ammar Faizi Dec 27 '20 at 14:10
  • argparse or fire are good options. See answers to this question: https://stackoverflow.com/q/20063/4590385 . Also, in the future, search Stack Overflow more before posting your question. The title of your question with "python appended" will yield many answers in google. – jeffhale Dec 27 '20 at 16:16

1 Answers1

1

You can use argparse module

import argparse

arg = argparse.ArgumentParser()
arg.add_argument('-n', '--name', required=True) 
arg.add_argument('-s', '--surname', required=True)
arg.add_argument('-d', '--day', required=True)
args = vars(arg.parse_args())

name, surname, day = args['name'], args['surname'], args['day']