Skip to content

Instantly share code, notes, and snippets.

@linuxluigi
Created February 28, 2017 08:16
Show Gist options
  • Save linuxluigi/0613c2c699d16cb5e171b063c266c3ad to your computer and use it in GitHub Desktop.
Save linuxluigi/0613c2c699d16cb5e171b063c266c3ad to your computer and use it in GitHub Desktop.
Python __main__.py parser example
import argparse
# import data2tabshop
# from data2tabshop import __version__
__version__ = '0.1.0'
__author__ = u'Steffen Exler'
def get_parser():
"""
Creates a new argument parser.
"""
parser = argparse.ArgumentParser('Data2TabShop')
version = '%(prog)s ' + __version__
parser.add_argument('--version', '-v', action='version', version=version)
parser.add_argument('--loadDatabase', '-l', type=load_database,
help='Load a File to Google Spreadsheet: -l data.xml', )
return parser
def load_database(file):
print("File will be loaded")
print(file)
def main(args=None):
"""
Main entry point for your project.
Args:
args : list
A of arguments as if they were input in the command line. Leave it
None to use sys.argv.
"""
parser = get_parser()
args = parser.parse_args(args)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment