another stupid question. global and local variables?

Hi! I am still working at the network code… well, here is the stuff

Edit: Well, I have tried several things, but I am stuck again… Why does the following happen?

bigfoot29@Gamer:~/pandachat$ ppython test.py 
test.py:14: SyntaxWarning: name 'USERS' is assigned to before global declaration
  def choking(self):
enumerate is already present in __builtin__
Warning: DirectNotify: category 'Interval' already exists
outside choking:  {'local1': 'mypass1'}
initialized
inside working:  {'local1': 'mypass1'}
After Choking:  {'local1': 'mypass2'}

Here is the according Code:

from direct.gui.DirectGui import *

USERS = {
        'local1' : 'mypass1'
        }

class Server(DirectObject):
        def __init__(self):
                print 'initialized'

        def working(self):
                print 'inside working: ',USERS

        def choking(self):

                USERS = {'local1' : 'mypass2'}
                global USERS

print 'outside choking: ',USERS

serverHandler = Server()
serverHandler.working()
serverHandler.choking()
print 'After Choking: ',USERS

I have defined USERS at the very start, but Python doesn’t seem to mind :frowning: Where is my problem?

Regards, Bigfoot29

It wants you to re-order these two lines:

                USERS = {'local1' : 'mypass2'}
                global USERS

To this:

                global USERS
                USERS = {'local1' : 'mypass2'}

But it would be better, rather than replacing the entire dictionary, simply to replace the element ‘local1’:


                USERS['local1'] = 'mypass2'

David