[New-bugs-announce] [issue40386] Strange behavior during invalid import of modules without if __name__ == "__main__"

wyz23x2 report at bugs.python.org
Fri Apr 24 23:57:29 EDT 2020


New submission from wyz23x2 <wyz23x2 at 163.com>:

This behavior:

Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> import this.main
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import this.main
ModuleNotFoundError: No module named 'this.main'; 'this' is not a package
>>> import this.main
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    import this.main
ModuleNotFoundError: No module named 'this.main'; 'this' is not a package
>>> del this
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    del this
NameError: name 'this' is not defined
>>> import this
>>>

This confuses users because the code of "this" is un the 1st time, but not the times after it. And "this" isn't actually imported after that; stranger is when you perform the correct import, it doesn't run.

Is this right?

----------
messages: 367253
nosy: wyz23x2
priority: normal
severity: normal
status: open
title: Strange behavior during invalid import of modules without if __name__ == "__main__"

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40386>
_______________________________________


More information about the New-bugs-announce mailing list