[Python-ideas] making a module callable

Ben Finney ben+python at benfinney.id.au
Sun Nov 24 22:26:07 CET 2013


Greg Ewing <greg.ewing at canterbury.ac.nz> writes:

> Ben Finney wrote:
> > So, definitely ‘sys.argv’ needs to continue having all command-line
> > arguments, including the command name used to invoke the program.
>
> That doesn't necessarily mean it has to be passed along with the
> arguments to a __main__() function, though. You can always extract it
> from sys.argv if you need it.

Yet the ‘__main__’ function needs to get the arguments as a parameter::

    def __main__(argv):

(or at least, that's how I've seen it done most commonly, and I agree
that it makes a good intreface for ‘__main__’ functions). Now you're
saying there is one command-line parameter which chould not come through
that interface? Why the special case?

> Arguably it's more convenient to get it from there, since you're most
> often to want it for things like formatting error messages, which are
> probably not happening right inside the main function.

It's more convenient to look in “the sequence of command-line
parameters” for all the command-line parameters, without special-casing
the command name.

-- 
 \           “If [a technology company] has confidence in their future |
  `\      ability to innovate, the importance they place on protecting |
_o__)     their past innovations really should decline.” —Gary Barnett |
Ben Finney



More information about the Python-ideas mailing list