473,320 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Note on PEP 299

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/pyt...ch/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 '06 #1
3 1162

<be************@lycos.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
>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/pyt...ch/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

Jul 21 '06 #2
http://home.comcast.net/~faulkner612...thon/mainer.py
turns
if __name__ == '__main__': sys.exit(main(sys.argv))
into
import mainer

be************@lycos.com 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/pyt...ch/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 21 '06 #3
Faulkner:
http://home.comcast.net/~faulkner612...thon/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 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: R. Rajesh Jeba Anbiah | last post by:
http://www.php.net/ob_end_clean#33484 Is the note is valid? I have tested in many way, but the result somehow shows that "If-Modified-Since" header is processed by the server than as told in the...
0
by: John Lenton | last post by:
In the fnctl docs for both python 2.3 and 2.4 there is a note at the bottom that says The os.open() function supports locking flags and is available on a wider variety of platforms than the...
6
by: Orchid | last post by:
I have 2 fields with Radio button Data Type, and both fields with more than one options. On Field1, I want the user to select option1, then Field2 is shown and able to select. If the user selects...
1
by: Asbjørn Ulsberg | last post by:
I'm writing a little C# / DirectSound piano which uses SecondaryBuffer to play .wav-files. The SecondaryBuffer has a Frequenzy property which I set to modulate the .wav file into playing the right...
0
by: Patrick Dugan | last post by:
Can anyone point me to an example of reading an Outlook Note to get the text? I want to somehow open a specified note and grab the text within it. I'm using VB.NET for a smart device (in this case...
3
by: Li Pang | last post by:
Hi, I wrote the following codes to read messages. They work fine for Outlook 2002 but fails for 2003. My felling it may be a bug of Outlook 2003. Anybody has experience on that? Thanks in...
7
by: Dan | last post by:
Hi, What is the best way to set up a "Note block" on a web page with CSS. This should consist of a colored box that contains an image on the left, and left-justified text floating to the right. ...
3
Shashi Sadasivan
by: Shashi Sadasivan | last post by:
hi, i have an issue with joining some table. i have 3 tables. product - (productID, total) items - (productID, itemNo, total) note - (noteID, productID, note) each product has one or more...
1
by: sudermatt | last post by:
This one is completely baffling. DB Enviornment: MSSQL database Code Environment: ASP / VBscript (obviously) Problem: data from an nText field disappears from conn.execute(sql) recordset. ...
3
by: waqasahmed996 | last post by:
Hi, I want to note time when user is logout. I can note time when user login and when logout properly(use button of logout). But if user is not used button and he closed his browser or...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.