[issue19499] import this is cached in sys.modules
Terry J. Reedy added the comment: Having import this behave differently from any other import is counter-intuitive I agree. My proposal (by design) does not change the property of executing only when first imported. I merely proposed that the text either start as cleartext or that the decrypted text be saved as a module attribute. *This* would make 'this' *more* like normal modules. Having side-effect code executed on import, as opposed to when running as main, is unusual. (Idlelib.idle is another intentional example, and one which currently has the same problem.) But I agree that this unusual behavior should remain for both. Having module code that is intentionally obfuscated and as about as inefficient as possible without being totally ridiculous is, I hope, unique, and not at all like other modules. Even if Tim wants to keep the literal encrypted, and the rot13 codec is not available in Py3 (?), the decoding would, I believe, be much more efficient using str.translate. Or the text could be encoded and decoded with one of the pairs in the binascii or base64 modules. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19499 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19499] import this is cached in sys.modules
Tim Peters added the comment: Reassigned to Barry, since he wrote this module ;-) FWIW, I wouldn't change it. It wasn't intended to be educational, but a newbie could learn quite a bit by figuring out how it works. -- assignee: tim.peters - barry nosy: +barry ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19499 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19499] import this is cached in sys.modules
Barry A. Warsaw added the comment: I completely agree with Tim. The 'this' module was a *joke* and a stealthy one at that. http://www.wefearchange.org/2010/06/import-this-and-zen-of-python.html About the only thing I'd support is adding some comments to the code to either explain what's going on a little better, or provide some history to what this module is and why it's there. Then again, if you want to do that, please be sure to also add some documentation, but you better make it *funny*. :) -- resolution: - wont fix status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19499 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19499] import this is cached in sys.modules
Changes by Gregory P. Smith g...@krypto.org: -- nosy: -gregory.p.smith ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19499 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19499] import this is cached in sys.modules
Antoine Pitrou added the comment: Terry is right here. The this module doesn't seem to have been thought as an educational tool in the first place. -- nosy: +pitrou ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19499 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19499] import this is cached in sys.modules
Ezio Melotti added the comment: I think this should be closed as won't fix. Having import this behave differently from any other import is counter-intuitive (students will start asking why if I reimport 'this' the code gets executed every time but it doesn't work with my module?). If they want to read the Zen over and over again they can check PEP 20. -- nosy: +ezio.melotti ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19499 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19499] import this is cached in sys.modules
Terry J. Reedy added the comment: The current ugly, implicit, complex ROT13? + custom decoder version of this.py violates the initial tenets that it prints. I suppose that is an intentional joke. If it were explicit and simple: text = '''title text lines ...''' print(text) then people could follow up import this with this.text and learn something about accessing module attributes. -- nosy: +terry.reedy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19499 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19499] import this is cached in sys.modules
Georg Brandl added the comment: Whatever we decide to do here, it **must** also be done for antigravity.py. -- nosy: +georg.brandl ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19499 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19499] import this is cached in sys.modules
R. David Murray added the comment: It seems to me that having import this work more than once would teach a beginner the *wrong* lesson about how python import works. So I agree that it should be a teaching moment, not a bug to be fixed. -- nosy: +r.david.murray ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19499 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19499] import this is cached in sys.modules
Mark Lawrence added the comment: If it ain't broke don't fix it. -- nosy: +BreamoreBoy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19499 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19499] import this is cached in sys.modules
Eric Snow added the comment: +0 to just doing a reload. At the point you show someone import this, it may be premature to be explaining reloading to them. Python is great because you usually don't have to hand-wave through some concepts in order to explain others. [1] Also, under Python 3 you have to import reload() separately: from imp import reload reload(this) [1] http://www.boredomandlaziness.org/2011/08/scripting-languages-and-suitable.html -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19499 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19499] import this is cached in sys.modules
Georg Brandl added the comment: IMO the fact that importing happens only once is also a very important one, so much the better this helps in learning it early. The bad thing is that opening this.py to see what's happening will not really enlighten the beginner :) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19499 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19499] import this is cached in sys.modules
New submission from Raymond Hettinger: The this module doesn't import functions; instead, it prints directly to stdout. Accordingly, there is no reason to cache this module in sys.modules. Ideally, a learner should be able to type import this more than once in a Python session. -- components: Library (Lib) messages: 202183 nosy: rhettinger priority: low severity: normal status: open title: import this is cached in sys.modules type: enhancement versions: Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19499 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19499] import this is cached in sys.modules
Tim Peters added the comment: Special cases aren't special enough to break the rules. ;-) -- nosy: +tim.peters ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19499 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19499] import this is cached in sys.modules
Eric Snow added the comment: You could add the following to the bottom of this.py: import sys del sys.modules['this'] -- nosy: +eric.snow ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19499 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19499] import this is cached in sys.modules
Raymond Hettinger added the comment: FWIW, a question about this has come up on multiple occasions when I teach Python classes. -- assignee: - tim.peters ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19499 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19499] import this is cached in sys.modules
Gregory P. Smith added the comment: I'd take their question as an educational opportunity. reload(this) -- nosy: +gregory.p.smith ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19499 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19499] import this is cached in sys.modules
Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com: -- nosy: +Arfrever ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19499 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com