Book Image

Daniel Arbuckle's Mastering Python

By : Daniel Arbuckle
Book Image

Daniel Arbuckle's Mastering Python

By: Daniel Arbuckle

Overview of this book

Daniel Arbuckle's Mastering Python covers the basics of operating in a Python development environment, before moving on to more advanced topics. Daniel presents you with real-world solutions to Python 3.6 and advanced-level concepts, such as reactive programming, microservices, ctypes, and Cython tools. You don't need to be familiar with the Python language to use this book, as Daniel starts with a Python primer. Throughout, Daniel highlights the major aspects of managing your Python development environment, shows you how to handle parallel computation, and helps you to master asynchronous I/O with Python 3.6 to improve performance. Finally, Daniel will teach you the secrets of metaprogramming and unit testing in Python, helping you acquire the perfect skillset to be a Python expert. Daniel will get you up to speed on everything from basic programming practices to high-end tools and techniques, things that will help set you apart as a successful Python programmer.
Table of Contents (13 chapters)

Making a package executable via Python -m

In the previous chapter, we ran command-line tools, such as doctest and venv, by typing in the python3 -m command followed by the name of the tool we wanted it to run:

What were we actually asking Python to do when we did that?

The -m command-line switch for Python tells it to run a module. It uses the same mechanism to find the module that it would if we'd used an import statement with the module's name and then it executes it.

However, venv isn't a module, it's a package. So, what's happening when we use python -m venv? We gave Python a package name, but we didn't give it a module name inside the package that it should run. When that happens, Python looks for a module named __main__ in the package and runs that:

So, python -m venv means the same thing as python -m venv.__main__.

Any module that's...