Application and package of the same name

Skip Montanaro skip.montanaro at gmail.com
Sat Oct 21 09:27:38 EDT 2017


This is actually a common pattern I see when teaching the language. For
example, when a student wants to test out a package like requests many
seem to initially want to create a requests.py module. Then they become
very confused when they get an AttributeError on requests.get().


That I should fall prey to this after using Python for over 20 years...
Should I be humbled, ashamed, delighted that I unwittingly demonstrated
something I've seen in others' code?

The sequence of events here was that I actually did have my main program
inside the package, but wanted to separate the two, since the package is
installed for clients of the allocation to use. As I was moving the
application into a Docker environment, it made sense to extract the main
program from the package and copy it separately into the image. I just git
mv'd the file from the package directory to the scripts directory, and it
stopped working. I should have realized right then and there what I'd done
wrong, but I got hung up thinking I'd done something wrong with absolute
imports.

Skip



More information about the Python-list mailing list