[Python-ideas] start, test, init

Nick Coghlan ncoghlan at gmail.com
Sun Dec 1 22:13:56 CET 2013


On 2 Dec 2013 06:34, "Ron Adam" <ron3200 at gmail.com> wrote:
>
>
>
> On 12/01/2013 06:45 AM, spir wrote:
>>
>> # __main__ = start
>> def start (args):
>>      init()
>>      # process args
>>      ...
>>
>>
>> What do you think? (bis)
>
>
> I think you are describing good programming practices for larger modules.
And I think most people who have been programming in python for any length
of time develop some form of what you are describing.
>
> The only difference is that they wouldn't need the conditional logic at
the bottom of the module.  But that also serves as bit of self
documentation as to what the module or script does, is more flexible, and
only adds a line or two if the rest is put into functions or classes.
>
>
> As for the testing case... I'd like for python to have a -t option that
only sets a global name __test__ to True.  Then that covers most of your
use cases without adding a whole lot.  Sometimes less is more.
>
>    if __test__:
>        test()
>    elif __name__ == '__main__':
>        main()
>
> That's just one possible combination of using __test__ and __name__.

Oh, interesting. Such an option could also alter -O and -OO to keep assert
statements.

I'd love to see that idea elaborated further, as there are a variety of
questions around how it might work in practice (Compile time constant like
__debug__? Always False builtin shadowed in the main module? If it works
like __debug__ and/or affects -O and -OO, does it need a new naming
convention in the pycache directory?)

Cheers,
Nick.

>
> Cheers,
>    Ron
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131202/1ca6d027/attachment.html>


More information about the Python-ideas mailing list