I'm a Python beginner and have successfully gotten my first program with CLI parameters passed in to run. Got lots of help from this Handling command line options.
My question is: Why in Example 5.45 a separate def main(argv)
has been used, instead of calling the try/except
block within __main__
itself.
Example 5.45
def main(argv):
grammar = "kant.xml"
try:
opts, args = getopt.getopt(argv, "hg:d", ["help", "grammar="]) 2
except getopt.GetoptError:
usage()
sys.exit(2)
...
if __name__ == "__main__":
main(sys.argv[1:])
Hope someone versed in Python could share your wisdom.
TIA - Ashant