[nbdev] is there a way to export a "if __name__ == "__main__"" clause?

Running something like this doesn’t fly in jupyter:

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    args = parser.parse_args()
    main(args)

… but I’d like for this to be included in the .py so folks can call my script from the command line. Is there a way to make that happen in nbdev?

Does this help? https://github.com/pete88b/decision_tree/blob/master/72_if__name__.ipynb

1 Like

Works great. A nice way to delineate argparse code in particular for notebook vs. script.