【发布时间】:2014-05-11 16:03:52
【问题描述】:
我正在创建一个登录系统,在注册时要求用户输入用户名和密码。我使用了一个函数来检查用户名是否有效,然后根据要求查看密码是否有效。(用户名不能已经在使用,必须包含字母)(密码必须包含大写、小写和数)。用户名函数完美运行,但由于某种原因在密码函数中我收到错误: AttributeError: 'builtin_function_or_method' object has no attribute 'isdigit' 有谁知道我在使一个函数和另一个函数之间的两个函数之间做的不同不是。谢谢。
def Username(user_name):
user_names = open('Username list.txt', 'r+')
uname_list = user_names.readlines()
char_user = [user_name]
for i in range(len(uname_list)):
uname_list[i] = uname_list[i].strip('\n')
for i in range(len(uname_list)):
if uname_list[i] == user_name:
return 'username already taken'
for i in range(len(char_user)):
if char_user[i].isspace() == True:
return 'username cannot contain spaces'
if user_name.isdigit() == True:
return 'username must contain letters'
elif len(user_name) < 4 or len(user_name) > 12:
return 'username must be between 4 and 12 characters'
else:
user_names.write(str(user_name + '\n'))
file.close(user_names)
return True
def Password(password, p2):
passwords = open('Password list.txt', 'r+')
if password != p2:
return 'you did not enter the same password twice'
elif password.isdigit() == True:
return 'username must contain letters'
elif password.islower() == True:
return 'username must contain a capital letter'
elif password.isupper() == True:
return 'username must contain a lower case letter'
elif password.isalpha() == True:
return 'username must contain a number'
elif len(user_name) < 4 or len(user_name) > 12:
return 'username must be between 4 and 12 characters'
else:
passwords.write(str(password + '\n'))
return True
print 'What would you like your username to be?'
print 'Your username must be between 4 and 12 characters, contain letters and not contain any spaces'
user_name = raw_input()
valid = Username(user_name)
while valid != True:
print valid
user_name = raw_input()
valid = Username(user_name)
print 'enter your password twice below for validication'
password = raw_input()
password2 = raw_input()
valid = Password(password,password2)
while valid != True:
print valid
print 'enter your password twice below'
password = raw_input
password2 = raw_input
valid = Password(password,password2)
程序运行时会发生什么。
'''What would you like your username to be?
Your username must be between 4 and 12 characters, contain letters and not contain any spaces
Test
enter your password twice below for validication
Your password must include capital letters, lowercase letters, numbers and be betweeen 4 and 12 characters
testing
testing
username must contain a capital letter
enter your password twice below
AttributeError: 'builtin_function_or_method' object has no attribute 'isdigit'''
【问题讨论】:
-
只是想知道我做了什么导致这个问题被否决了吗?有没有人对未来的问题有任何建议
-
发布完整的回溯将是一个好的开始,并解释您迄今为止为解决问题所做的尝试。
-
感谢您的建议
标签: python function login user-defined-functions attributeerror