File Templates (Python)

Executable Python File

#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
"""Short description of what this file does"""
 
import sys
import os
import logging
import argparse
 
 
logger = logging.getLogger(os.path.basename(sys.argv[0]))
 
 
def main(argv):
    """Main method of the file."""
 
    # Parse arguments
    parser = argparse.ArgumentParser(description='Does fancy stuff.')
    parser.add_argument('-v', '--verbose', action='store_true',
                        help='log verbose')
    args = parser.parse_args(argv[1:])
 
    # Logging
    if args.verbose:
        log_level = logging.DEBUG
    else:
        log_level = logging.INFO
    log_format = '{levelname:8} - {name} - {message}'
    logging.basicConfig(level=log_level, format=log_format, style='{')
 
    # Actual code...
 
    return 0
 
 
if __name__ == '__main__':
    sys.exit(main(sys.argv))
Log In