object scope
J. Peng
jpeng at block.duxieweb.com
Sun Jan 20 23:21:19 EST 2008
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
More information about the Python-list
mailing list