Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Daniel Arbuckle???s Mastering Python

You're reading from   Daniel Arbuckle???s Mastering Python Build powerful Python applications

Arrow left icon
Product type Paperback
Published in Jun 2017
Publisher Packt
ISBN-13 9781787283695
Length 274 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Daniel Arbuckle Daniel Arbuckle
Author Profile Icon Daniel Arbuckle
Daniel Arbuckle
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Python Primer 2. Setting Up FREE CHAPTER 3. Making a Package 4. Basic Best Practices 5. Making a Command-Line Utility 6. Parallel Processing 7. Coroutines and Asynchronous I/O 8. Metaprogramming 9. Unit Testing 10. Reactive Programming 11. Microservices 12. Extension Modules and Compiled Code

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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image