Note on PEP 299

Discussion in 'Python' started by bearophileHUGS@lycos.com, Jul 20, 2006.

  1. Guest

    I don't like much the syntax of:
    if __name__ == '__main__':

    Some time ago I have read this PEP:
    http://www.python.org/dev/peps/pep-0299/

    And why it was refused:
    http://mail.python.org/pipermail/python-dev/2006-March/062955.html

    I think the name of the standard main function may be just main(), so
    there isn't the problem with the import (and *maybe* the problem with
    multiple Python versions can be ignored with Python 3.0).

    If a module contains the main(), the main() is executed when the module
    is run alone. Otherwise you can import the module, with the main()
    function managed as a normal function.

    Bye,
    bearophile
     
    , Jul 20, 2006
    #1
    1. Advertising

  2. Terry Reedy Guest

    <> wrote in message
    news:...
    >I don't like much the syntax of:
    > if __name__ == '__main__':
    >
    > Some time ago I have read this PEP:
    > http://www.python.org/dev/peps/pep-0299/
    >
    > And why it was refused:
    > http://mail.python.org/pipermail/python-dev/2006-March/062955.html
    >
    > I think the name of the standard main function may be just main(), so
    > there isn't the problem with the import (and *maybe* the problem with
    > multiple Python versions can be ignored with Python 3.0).


    This idea, and a couple of variations, have come up in the Py3 discussions,
    so something might be tried.

    tjr
     
    Terry Reedy, Jul 21, 2006
    #2
    1. Advertising

  3. faulkner Guest

    http://home.comcast.net/~faulkner612/programming/python/mainer.py
    turns
    if __name__ == '__main__': sys.exit(main(sys.argv))
    into
    import mainer

    wrote:
    > I don't like much the syntax of:
    > if __name__ == '__main__':
    >
    > Some time ago I have read this PEP:
    > http://www.python.org/dev/peps/pep-0299/
    >
    > And why it was refused:
    > http://mail.python.org/pipermail/python-dev/2006-March/062955.html
    >
    > I think the name of the standard main function may be just main(), so
    > there isn't the problem with the import (and *maybe* the problem with
    > multiple Python versions can be ignored with Python 3.0).
    >
    > If a module contains the main(), the main() is executed when the module
    > is run alone. Otherwise you can import the module, with the main()
    > function managed as a normal function.
    >
    > Bye,
    > bearophile
     
    faulkner, Jul 21, 2006
    #3
  4. Guest

    Faulkner:
    > http://home.comcast.net/~faulkner612/programming/python/mainer.py


    It's a bit of magic, I'll test it more, but it seems to work binding
    the main() with Psyco too.
    I have changed it a little (removed argv passed to the main and the
    import of type, etc).
    I don't know if/when I'll use it, but it seems nice enough.

    Bye,
    thank you,
    bearophile
     
    , Jul 21, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christoph Becker-Freyseng

    PEP for new modules (I read PEP 2)

    Christoph Becker-Freyseng, Jan 15, 2004, in forum: Python
    Replies:
    3
    Views:
    374
    Gerrit Holl
    Jan 16, 2004
  2. Stephen R Laniel
    Replies:
    160
    Views:
    2,216
    Hendrik van Rooyen
    Jul 22, 2007
  3. Hamilton, William
    Replies:
    3
    Views:
    352
    Donn Cave
    Jul 11, 2007
  4. Ben Finney

    PEP 299 and unit testing

    Ben Finney, Oct 29, 2007, in forum: Python
    Replies:
    5
    Views:
    298
    Ben Finney
    Oct 29, 2007
  5. Lie
    Replies:
    25
    Views:
    740
    Dafydd Hughes
    Dec 18, 2007
Loading...

Share This Page