J. Peng
1/21/2008 4:21:00 AM
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.
>
>
sorry the before code seems be disordered,re-posted it.
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