python请各位帮忙看一下什么地方有问题谢谢
#!/usr/bin/env python
db = {}
def newuser():
prompt = 'login desired:'
while True:
name = raw_input(prompt)
if db.has_key(name):
prompt = 'name taken, try another: '
continue
else:
break
pwd = raw_input('passwd: ')
db[name] = pwd
def olduser():
name = raw_input('login: ')
pwd = raw_input('passwd: ')
passwd = db.get(name)
if passwd == pwd:
print 'welcome back',name
else:
print 'login incorrect'
def showmenu():
prompt = """
(N)ew User Login
(E)xisting User Login
(Q)uit
Enter choice: """
done = 0
while not done:
chosen = 0
while not chosen:
try:
choice = raw_input(prompt)[0]
except (EOFError, KeyboardInterrupt):
choice = 'q'
print '\nYou picked: [%s]' % choice
if choice not in 'neq':
print 'invalid menu opthion, try again'
else:
chosen = 1
if choice == 'q': done = 1
if choice == 'n': newuser()
if choice == 'e': olduser()
if _name_ == '_main_':
showmenu()
以上是源码,执行后出现以下问题
Traceback (most recent call last):
File "userlogin.py", line 46, in ?
if _name_ == '_main_':
NameError: name '_name_' is not defined
请问怎么解决。
db = {}
def newuser():
prompt = 'login desired:'
while True:
name = raw_input(prompt)
if db.has_key(name):
prompt = 'name taken, try another: '
continue
else:
break
pwd = raw_input('passwd: ')
db[name] = pwd
def olduser():
name = raw_input('login: ')
pwd = raw_input('passwd: ')
passwd = db.get(name)
if passwd == pwd:
print 'welcome back',name
else:
print 'login incorrect'
def showmenu():
prompt = """
(N)ew User Login
(E)xisting User Login
(Q)uit
Enter choice: """
done = 0
while not done:
chosen = 0
while not chosen:
try:
choice = raw_input(prompt)[0]
except (EOFError, KeyboardInterrupt):
choice = 'q'
print '\nYou picked: [%s]' % choice
if choice not in 'neq':
print 'invalid menu opthion, try again'
else:
chosen = 1
if choice == 'q': done = 1
if choice == 'n': newuser()
if choice == 'e': olduser()
if _name_ == '_main_':
showmenu()
以上是源码,执行后出现以下问题
Traceback (most recent call last):
File "userlogin.py", line 46, in ?
if _name_ == '_main_':
NameError: name '_name_' is not defined
请问怎么解决。
作者: ybbdnvjfd 发布时间: 2011-05-26
if _name_ == '_main_':
替换
if __name__ == '__main__':
什么书这么垃圾啊!
替换
if __name__ == '__main__':
什么书这么垃圾啊!
作者: ccporxy 发布时间: 2011-05-26
我的问题,别埋怨书呵呵,请问好的学习python的方式吗
作者: ybbdnvjfd 发布时间: 2011-05-26