[Python-ideas] Just main (original) (raw)
Andrew McNabb amcnabb at mcnabbs.org
Mon Jun 18 20:05:26 CEST 2012
- Previous message: [Python-ideas] Just __main__
- Next message: [Python-ideas] Just __main__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, Jun 18, 2012 at 01:25:11PM -0400, Mike Graham wrote:
That being said, I'm -0 on the feature. I don't think it's really much easier to explain or worth any effort.
I agree that having a boolean called "main" wouldn't add much value, but I believe that recognizing a function called "main" could potentially add a bit more value.
After executing the body of a script, the interpreter would automatically call the "main" function if it exists, and exit with its return value. Thus:
def main(): return 42
would be roughly equivalent to:
if name == 'main': sys.exit(42)
It might make sense to have "python -i" not call the "main" function, making it easier to interact with a script after the time that its methods and global variables are all defined but before the time that it enters main.
I'm not sure if a "main" function would add enough value, but I think it would add more value than a "main" boolean.
-- Andrew McNabb http://www.mcnabbs.org/andrew/ PGP Fingerprint: 8A17 B57C 6879 1863 DE55 8012 AB4D 6098 8826 6868
- Previous message: [Python-ideas] Just __main__
- Next message: [Python-ideas] Just __main__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]