Python - Main (Entry Point)

Card Puncher Data Processing

Python - Main (Entry Point)

About

Main In Python.

Specification

https://packaging.python.org/specifications/entry-points/

Type

Package

init

def main():
    """Entry point for the application script"""
    print("Call your main application code here")

executable scripts

To provide executable scripts, use entry points in preference to the “scripts” keyword. Entry points provide cross-platform support and allow pip to create the appropriate form of executable for the target platform.

For example, the following would provide a command called sample which executes the function main from this package when invoked:

entry_points={  # Optional
        'console_scripts': [
            'sample=sample:main',
        ],
    },

Script

When you want to make a script executable, the if statement makes that The code is not executed when the script is imported as a module.

import sys

def main(argv):
    # my code here

if __name__ == "__main__":
    main(sys.argv)

where __name__ has the value:

  • foo when the module is imported
  • or __main__ when executed from Python.

Documentation / Reference







Share this page:
Follow us:
Task Runner