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

Brett Cannon brett at python.org
Fri Apr 20 19:16:48 CEST 2007


On 4/20/07, Jim Jewett <jimjjewett at gmail.com> wrote:

On 4/19/07, Brett Cannon <brett at python.org> wrote:

> ... By leaving the _name_ attribute in a module alone and > setting a module attribute named _main_ to a true value for the > main module (and thus false in all others) ... Part of me says that you are already proposing the right answer, as these alternatives are just a little too hackish. Still, they are good enough that they should be listed in the PEP, even if only as rejected alternatives. (1) You could add a builtin main that is false. The real main module would mask it, but no other code would need to change. Con: Another builtin, and this one wouldn't even make sense as an independent object. (2) You could special-case the import to use file instead of name when name == "main" Con: may be more fragile. (3) You could set name to (an instance of) a funky string subclass that overrides eq. Con: may be hard to find exactly the right behavior. Examples: What should str(name) do? Maybe main should be the primary value, and split should be overridden?

Yeah, I don't like any of them. =) I will add them to the PEP in a Rejected Ideas section.

-Brett



More information about the Python-ideas mailing list