0

For example I have function that takes --config argument from command line. So to launch it from console I have to enter following:

>>> my_function --config

I want to create file like new_func.py and launch my_function --config from here.

How can I do this?

micgeronimo
  • 2,069
  • 5
  • 23
  • 44
  • Do you have a more specific example? Otherwise it sounds like you need to import sys and then store the argument in a variable using sys.argv. An example would be nice :) – Onedot618 Feb 11 '15 at 12:17

1 Answers1

0

Use argparse module:

import argparse

parser = argparse.ArgumentParser(description='Command line exemple.')
parser.add_argument('--config', dest='fileconf', action='store',
                   help='my argument description)')

args = parser.parse_args()
print args.fileconf # do something with fileconf value

enter image description here

felipsmartins
  • 13,269
  • 4
  • 48
  • 56