If I am using argparse and an if __name__ == '__main__'
test in a script that I would also like to use as a module, should I import argparse under that test and then initialize it? None of the style guides I have found mention using argparse in scripts and many examples of argparse scripting do not use the 'if name' test or use it differently. Here is what I have been going with so far:
#! /usr/bin/env python
def main(name):
print('Hello, %s!' % name)
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description = 'Say hello')
parser.add_argument('name', help='your name, enter it')
args = parser.parse_args()
main(args.name)
Should I import argparse with my other modules at the top and configure it in the body of the script instead?