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

Christian Heimes lists at cheimes.de
Sat Apr 21 16:25:57 CEST 2007


Steven Bethard wrote:

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...?

This is just my humble opinion. I'm new to Python core development.

Well, in my opinion a new module level var like main isn't worth to add when it is just boolean flag. With the proposed addition of sys.main the same information is available with just few more characters to type. If I recall correctly Python is trying to get rid of global variables in Python 3000.

I don't think it's hard to add - even for me although I know less about the Python core. I'm more worried about the side effect when people have already used main as a function. The problem is in 2to3.

If you like to introduce main why not implement http://www.python.org/dev/peps/pep-0299 ? It proposes a main(argv) module level function that replaced the "if name == 'main'" idiom. The main function follows the example of other programming languages like C, C# and Java.

I'm aware of the fact that the PEP was rejected but I think it's worth to discuss it again.

Christian



More information about the Python-ideas mailing list