Skip to Content
Intuitive Python
book

Intuitive Python

by David Muller
May 2021
Intermediate to advanced
142 pages
3h 37m
English
Pragmatic Bookshelf
Content preview from Intuitive Python

Dodging Wildcard Variable Shadowing

Few things are more destructive for a code base then a programmer operating under flawed assumptions. We want to write code that makes it clear to others what calling a piece of code does and what effects it might have.

In an earlier chapter, you learned how to use flake8 to catch certain types of errors before you even run your Python code. One of the dangerous classes of errors that flake8 helps you avoid is variable shadowing from * (“wildcard”) imports.

Consider the following toy file that provides two methods for managing dinosaurs:

 from​ ​veterinarian​ ​import​ *
 from​ ​lab​ ​import​ *
 
 def​ ​euthanize_dinosaurs​():
 for​ dinosaur ​in​ get_dinosaurs():
 print​(f​"Euthanizing ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Pythonic Programming

Pythonic Programming

Dmitry Zinoviev
Python for Geeks

Python for Geeks

Muhammad Asif

Publisher Resources

ISBN: 9781680508635Errata Page