On Mon, 25 Mar 2019 at 20:34, Cameron Simpson <c...@cskk.id.au> wrote: > Clearly the above needs to accomodate this, possibly with a fallback > guess. Is sniffing the end components of __file__ at all sane? ending in > idlelib/pyshell.py or pyshell.py? Or is that just getting baroque? > > I don't think these are strictly the same from some kind of purist > viewpoint: the path might be anything - _is_ it reasonable to suppose > that it has a module name (== importable/finding through the import > path)?
Directly executing files from inside Python packages is explicitly unsupported, and nigh guaranteed to result in a broken import setup, as relative imports won't work, and absolute imports will most likely result in a second copy of the script module getting loaded. The problem is that __main__ always thinks it is a top-level module for directly executed scripts - it needs the package structure information from the "-m" switch to learn otherwise. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com