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

Aahz aahz at pythoncraft.com
Sat Apr 21 00:30:19 CEST 2007


On Fri, Apr 20, 2007, Brett Cannon wrote:

On 4/20/07, Christian Heimes <lists at cheimes.de> wrote:

What about import sys if name == sys.main: ... You won't have to introduce a new global module var name and it's easy to understand for newbies and experienced developers. The code is only executed when the name of the current module is equal to the executed main module (sys.main). IMO it's much less PIT...B then introducing main. True, but it does introduce an import for a module that may never be used if the module is not being executed. That kind of sucks for minor performance reasons. But what do other people think?

Looks good to me! sys is essentially guaranteed to be imported, so you're only wasting a few cycles to bring it into the module namespace.

Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/

Help a hearing-impaired person: http://rule6.info/hearing.html



More information about the Python-ideas mailing list