if __name__ == "__main__": 的使用

#!/usr/bin/env python
from qq.lib.a2 import register
from qq.lib.a3 import login

def main():
    while True:
        choice = input("登陆:1,注册:2")      
        if choice == "1":
            user = input("用户名:")
            pwd = input("密码:")
            ret = login(user, pwd)
            if ret:
                print("登录成功")
                break
            else:
                print("登录失败")
        elif choice == "2":
            user = input("用户名:")
            pwd = input("密码:")
            ret = register(user, pwd)
            if ret:
                print("注册成功")
                break
            else:
                print("注册失败")
if __name__ == "__main__":
    main()
#!/usr/bin/env python
import hashlib
def md5(arg):
    ooo = hashlib.md5(bytes('taochen', encoding='utf-8'))
    ooo.update(bytes(arg, encoding='utf-8'))
    return ooo.hexdigest()
a1.py
#!/usr/bin/env python
import hashlib
from qq.lib.a1 import md5
def register(user, pwd):
    with open('db', 'a', encoding=' utf-8') as f:
        temp = md5(user) + '|' + md5(pwd)
        f.write(temp + "\n")
        return True
a2.py
#!/usr/bin/env python
import hashlib
from qq.lib.a1 import md5
def login(user,pwd):
    with open('db', 'r', encoding='utf-8') as f:
        for line in f:
            u, p = line.strip().split('|')
            if u == md5(user) and p ==md5(pwd):
                 return True
    return False
a3.py

 

posted @ 2017-02-14 21:59  失落的黎明  阅读(1193)  评论(0编辑  收藏  举报