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

rantingrick rantingrick at gmail.com
Mon Oct 3 16:10:15 EDT 2011


On Oct 3, 2:14 pm, Dave Angel <da... at ieee.org> wrote:

> Like it or not, there are plenty of globals already there, one of them
> being __name__ .  All the built-ins are effectively global, and so
>   is any function they define at top-level.

I keep wondering if that was another PyWart? I believe (and hindsight
is 20-20) that all the built-in modules should have been protected by
a top-level namespace. Something succicent, something like "py"...

from py.archive import zipfile, tarfile
from py.gui import Tkinter
from py.markup import HTMLParser

...and voila, no more clashes with user defined modules!


> Likewise any top-level
> class, and any symbols imported with import or with from/import.  So I
> consider it impractical for the language to do something that
> self-discipline is required for.

Also for scoping.

py> count = 0
py> def foo():
...     global.count += 1
py> print count
1

Why? Well because many times i find myself wondering if this or that
variable is local or global -- and when i say "global" i am speaking
of module scope! The "global<DOT>" cures the ill.



More information about the Python-list mailing list