Problem with global variables

hg hg at nospam.org
Mon Apr 2 02:55:56 EDT 2007


Ed Jensen wrote:

> #! /usr/bin/env python
> 
> def tiny():
> bar = []
> for tmp in foo:
> bar.append(tmp)
> foo = bar
> 
> if __name__ == "__main__":
> foo = ['hello', 'world']
> tiny()


Like this ?

#! /usr/bin/env python

def tiny():
    bar = []
    gobal foo
    for tmp in foo:
        bar.append(tmp)
    foo = bar

if __name__ == "__main__":
    foo = ['hello', 'world']
    tiny()


hg




More information about the Python-list mailing list