J
J. Peng
Please see the code below,what's the scope for object "name"?
I thought it should be located in the while block, but it seems not
really,it can be accessed out of while (the db[name] statement).Thanks
in advance.
db = {}
def newuser():
prompt = 'login desired: '
while 1:
name = raw_input(prompt)
if db.has_key(name):
prompt = 'name taken, try another: '
continue
else:
break
pwd = raw_input('passwd: ')
db[name] = pwd
I thought it should be located in the while block, but it seems not
really,it can be accessed out of while (the db[name] statement).Thanks
in advance.
db = {}
def newuser():
prompt = 'login desired: '
while 1:
name = raw_input(prompt)
if db.has_key(name):
prompt = 'name taken, try another: '
continue
else:
break
pwd = raw_input('passwd: ')
db[name] = pwd