import sys # <-- importing a packagedefmain():# <-- function declaration
car = sys.argv[1]
print(f"Your favorite car is a {car}!") # <-- an "f-string"if __name__ == "__main__": # <-- only execute if run as the entry point
main() # <-- calling a function
$ python script.py "Mitsubishi Montero Sport"# <-- running a python module
Your favorite car is a Mitsubishi Montero Sport!
What is a Package?
Packages are a way of structuring Python’s module namespace by using “dotted module names”.
# executed when the package itself is invoked using -m from .app import run
if __name__ == "__main__":
run()
Anatomy of a Package (cont'd)
app.py
import sys
defmain():
car = sys.argv[1]
print(f"Your least favorite car is a {car}!")
$ python -m app "Chrysler PT Cruiser"
Your least favorite car is a Chrysler PT Cruiser!
Craigslist CLI
Search cars for sale
Find lowest priced cars
Save car images
Search multiple Craigslist regions at once
Craigslist CLI
Search cars for sale
$ python -m app \
"https://spokane.craigslist.org/d/cars-trucks-by-owner/search/cto?query=montero"
mitsubishi montero XlS 2002
Montero/Pajero SR Safari roof 1998
2002 Mitsubishi Montero Sport 2002
Craigslist CLI
Find lowest priced cars
$ python -m app --lowest \
"https://spokane.craigslist.org/d/cars-trucks-by-owner/search/cto?query=montero"
2002 Mitsubishi Montero Sport is the lowest priced vehicle at $650