Created
February 28, 2017 08:16
-
-
Save linuxluigi/0613c2c699d16cb5e171b063c266c3ad to your computer and use it in GitHub Desktop.
Python __main__.py parser example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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