[Python-ideas] PEP for executing a module in a package containing relative imports (original) (raw)

Josiah Carlson jcarlson at uci.edu
Sun Apr 22 19:39:57 CEST 2007


"Jim Jewett" <jimjjewett at gmail.com> wrote:

On 4/21/07, Brett Cannon <brett at python.org> wrote: > On 4/21/07, Josiah Carlson <jcarlson at uci.edu> wrote: > > After reading other posts in the thread, I'm going to put my support > > into the sys.main variant. It has all of the benefits of the builtin name > > == main, with none of the drawbacks (no builtin!), and only a slight > > annoyance of 'import sys', which is more or less free. > Yeah, I am starting to like it as well. Steven and Jim, what do you think? Better than adding a builtin. I'm not sure I like the idea of another semi-random object in sys either, though. (1) One of the motivations was importing. It looks like file already has sufficient information. I understand that relying on it (or on package?) seems a bit hacky, but is it really worse than adding something? (2) Is there a reason the main module can't appear in sys.modules twice, once under the alias "main"?

While it is unlikely, there may be cleanup issues when the process is ending.

# Equivalent to today if name == sys.modules["main"].name:

# Better than today if name is sys.modules["main"].name:

The above two should be equivalent unless the importer has a bad habit.

# What I would like (pending PEP I hope to write tonight) if thismodule is sys.modules["main"]:

While I would also very much like the ability to access this module, I don't believe that this necessarily precludes the use of a proper package.module naming scheme for all name values.



More information about the Python-ideas mailing list