Python: Do This, Not That!

Preface

This book shows how to write beautiful, idiomatic Python code with simple, effective examples. There are no long explanations, but the intention is to show and demonstrate preferred ways of writing code in Python. As such, the intended audience is for intermediate Python programmers looking to improve ways to write and express their code in a readable way while still preserving computational efficiency and effectiveness.

Under each major section, you will see two sub-sections: Don't Do This and Do This. Code under Don't Do This are discouraged, and following the adjective of Jeff Knupp [JeK], are harmful. Code under Do This are the encouraged, beautiful and idiomatic Pythonic way to write the code instead. All examples are geared for Python 3 (specifically, v3.7) and higher (though a lot of examples may work for Python 2).

Ideas and code examples are borrowed from [YaK, RaH, JeK].

To follow along and execute the code samples, you will need Docker installed. The Docker container is located on Docker Hub. After you have installed Docker, you may run the container as follows.

docker run -it \
 -p 8888:8888 \
 oneoffcoder/book-python-dothis

Note that this Docker container has Jupyter Lab running on port 8888. You may access Jupyter Lab at http://localhost:8888 when the Docker container is running.

About

One-Off Coder logo.

One-Off Coder is an educational, service and product company. Please visit us online to discover how we may help you achieve life-long success in your personal coding career or with your company’s business goals and objectives.

Bibliography

[YaK]

Intermediate python. https://book.pythontips.com/en/latest/index.html. Accessed: 2019-10-18.

[RaH]

Transforming code into beautiful, idiomatic python. https://www.youtube.com/watch?v=OSGv2VnC0go. Accessed: 2019-10-18.

[JeK] (1,2)

Writing idiomatic python. https://jeffknupp.com/writing-idiomatic-python-ebook/. Accessed: 2019-10-18.

Author

Jee Vang, Ph.D.