[Python-ideas] PEP for executing a module in a package containing relative imports (original) (raw)
Steven Bethard steven.bethard at gmail.com
Sat Apr 21 00:14:44 CEST 2007
- Previous message: [Python-ideas] PEP for executing a module in a package containing relative imports
- Next message: [Python-ideas] PEP for executing a module in a package containing relative imports
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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).
But you have to understand a few things to understand why this works. You have to know that name is the name of the module, and that if you want to find out the name of the main module, you need to look at sys.main. With the idiom::
if __main__:
all you need to know is that the main module has main set to true.
IMO it's much less PIT...B then introducing main.
Could you elaborate? Do you think it would be hard to introduce another module-level attribute (like we already do for name)? Or do you think that the code would be hard to maintain? Or something else...?
Steve
I'm not in-sane. Indeed, I am so far out of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy
- Previous message: [Python-ideas] PEP for executing a module in a package containing relative imports
- Next message: [Python-ideas] PEP for executing a module in a package containing relative imports
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]