osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] BDFL-Delegate appointments for several PEPs


On Mon, 25 Mar 2019 at 20:34, Cameron Simpson <cs at 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   |   ncoghlan at gmail.com   |   Brisbane, Australia