On 19 Feb 2007 09:04:19 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>Hi,
>
>I have the following code:
>
>colorIndex = 0;
>
>def test():
>     print colorIndex;
>
>This won't work.

Are you sure?

    [EMAIL PROTECTED]:~$ cat foo.py
    colorIndex = 0
    
    def test():
        print colorIndex
    
    test()
    [EMAIL PROTECTED]:~$ python foo.py
    0
    [EMAIL PROTECTED]:~$                                           

The global keyword lets you rebind a variable from the module scope.  It
doesn't have much to do with accessing the current value of a variable.

Jean-Paul
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to