Is it possible to create C-style "main" function in Python? (for teaching purposes)

Aivar Annamaa aivar.annamaa at gmail.com
Mon Oct 3 12:21:56 EDT 2011


Hi!

I'm looking for a trick or hidden feature to make Python 3 automatically
call a "main" function but without programmers writing `if __name__ ==
"__main__": ...`

I found rejected PEP 299, but i thought that maybe there's something new
already.

Here's why I want such a thing:
I'm teaching introductory programming course with Python. I've seen that
global variables attract beginners like honey attracts bees and this makes
teaching function parameters harder. When students learn functions, they
usually write their function definitions and function applications in the
same scope -- in top-level of the module (don't know the correct term for
it). This has the downside, that any variable introduced in top-level is
automatically visible in function definitions and I have hard time
convincing students not to use those variables in functions directly.

I've been thinking that it might be better for teaching if all program code
would be in functions. This would make "Hello World" a bit more difficult,
but would help teaching the "real thing" ie. functions.

best regards,
Aivar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111003/11b6354b/attachment.html>


More information about the Python-list mailing list