I am trying to pass a .py
file to ipython notebook environment.
I have never had to deal directly with argparse before. How do I rewrite the main()
As @nbro suggested, the following command should work:
args = parser.parse_args(args=[])
In addition, if you have required arguments in your parser, set them inside the list:
args = parser.parse_args(args=['--req_1', '10', '--req_2', '10'])
Where you previously used:
import argparse
parser = argparse.ArgumentParser(description="Dummy parser")
parser.add_argument("--req_1", type=int, required=True, help="required int 1")
parser.add_argument("--req_2", type=int, required=True, help="required int 2")
You can also see from the notebook all params:
print("see all args:", args)
print("use one arg:", args.req_1)
You can find more information in the docs: Parsing arguments