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

2020-04-24 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Trying using "import this" instead of "import this.main".

The latter does an "import this" and then attempts to load a "main" package 
that doesn't exist.  You're observed the expected behavior.  See 
https://docs.python.org/3/tutorial/modules.html#packages for more details.

Hope that clears-up your understanding of what is happening.

--
nosy: +rhettinger
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2020-04-24 Thread wyz23x2


Change by wyz23x2 :


--
type:  -> behavior

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2020-04-24 Thread wyz23x2


wyz23x2  added the comment:

Sorry, it's "of 'this' is run", not "un".

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2020-04-24 Thread wyz23x2


Change by wyz23x2 :


--
components: +Library (Lib)
versions: +Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2020-04-24 Thread wyz23x2


New submission from wyz23x2 :

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 "", line 1, in 
import this.main
ModuleNotFoundError: No module named 'this.main'; 'this' is not a package
>>> import this.main
Traceback (most recent call last):
  File "", line 1, in 
import this.main
ModuleNotFoundError: No module named 'this.main'; 'this' is not a package
>>> del this
Traceback (most recent call last):
  File "", line 1, in 
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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com