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

Ian Kelly ian.g.kelly at gmail.com
Mon Oct 3 18:41:08 EDT 2011


On Mon, Oct 3, 2011 at 2:10 PM, rantingrick <rantingrick at gmail.com> wrote:
> 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.

def add_from_input(num_lines):
    total = global.sum(global.int(global.input()) for i in
global.range(num_lines))
    global.print("The total is", total)

Yes, that's much better.



More information about the Python-list mailing list