On Sat, Mar 5, 2011 at 2:22 AM, Fred Drake <fdr...@acm.org> wrote: > On Fri, Mar 4, 2011 at 10:59 AM, <exar...@twistedmatrix.com> wrote: >> Something to consider here is how this will interact with Python files which >> are _not_ modules. I'm a little uneasy about having sys.modules["trial"] >> refer to the module defined by /usr/bin/trial. > > I've long held the position that modules and scripts are distinct, and > should never share a source file. All the work that's going into > dealing with this just reinforces my position.
While I actually have a lot of respect for that point of view (the traps in PEP 395 can be read as a list of justifications for it!), "python -m timeit", "python -m test", "python -m site" and assorted other instances in the stdlib disagree with it. I don't think a purity argument is going to fly here, because the practice of allowing executable modules is just so damn useful for utility functionality where a developer doesn't want to worry about global namespace collisions on the system path . If we turned every module we have in the stdlib with a little snippet of directly executable functionality at the bottom into an installed script, I assume the distro packagers would either outright ignore us or howl the place down with cries of namespace pollution (and they'd be right to do so - the "-m" switch *originated* in a discussion about making timeit easier to invoke on different parallel Python installations without running into namespace collision problems on the system path). Besides, this particular ship really sailed way back in the early days of Python's history when the "if __name__ == '__main__':" convention was established to allow the same source file to behave differently depending on how it was invoked (either as a module or as a script). All PEP 395 is about is trying to make the way that works line up more closely with people's intuitions. However, as a slight tangent, note that one of the positive side effects of the __main__.py file approach to directory and package execution is that it *does* promote keeping the script behaviour and the module behaviour in separate files. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com