首页 > 其他 > 详细

if __name__ == "__main__": 的使用

时间:2017-02-15 00:07:51      阅读:177      评论:0      收藏:0      [点我收藏+]
#!/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

 

if __name__ == "__main__": 的使用

原文:http://www.cnblogs.com/shiluoliming/p/6399401.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!