Any Python file can be considered a ‘module’, and can be
import-ed. This just runs the code in the file, and makes
the names of any objects in the module accessible using
dot-notation.
If we bundle our Python scripts into a collection of functions, we
can reuse those functions in other modules or in the Python
interpretter.
After turning our scripts into reusable modules, we can maintain
script-like behaviour using the idiom
if __name__ == "__main__".
argparse can be used to create sophisticated command
line interfaces.
The ‘best practices’ for Python packaging has changed a number of
times, and there are now many competing tools for accomplishing the same
task.
Be wary of information on this topic in online tutorials – not all
guides have been updated to use the most recent methods, and some advice
may no longer be relevant.