Hey Ned,

Thank you for mentioning the old and related issue.

In order to prevent confusion, I want to point out that the primary scenario that I meant is not that the file imports itself but another file in the same directory with the name of a module that is also installed in site-packages. Not sure if I made that clear in my original post?



On Wed, Nov 3, 2021 at 4:30 PM Ned Batchelder <ned@nedbatchelder.com> wrote:

On 11/2/21 6:03 AM, Florian Wetschoreck wrote:

Hello everyone:

The scenario/observation:
Beginners sometimes create scripts with the name of a package e.g. pandas.py or seaborn.py in order to test something.

There's a previous discussion about preventing importing a file into itself. It's a common beginner mistake: "I want to try out the random module, I will name my test program random.py".  Then they get a baffling error: "AttributeError: module 'random' has no attribute 'shuffle'".   If we make the actual error more apparent ("ImportError: module 'random' imported itself"), we might nip this error in the bud.

Thread: https://mail.python.org/archives/list/python-ideas@python.org/thread/XJIEQQ7FCTNVKB7SMRQS2IJSSANRDU26/#QOL54FGEDKYGX5J4UMBAUR74PGS3HEPD

--Ned.

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/VVQRV5TR2HUMAZUNPJAQ7VBVMOVO5RCH/
Code of Conduct: http://python.org/psf/codeofconduct/