码迷,mamicode.com
首页 > 其他好文 > 详细

if __name__ == "__main__": 的使用

时间:2017-02-15 00:07:54      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:out   color   ide   密码   bin   lap   closed   write   iges   

#!/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__": 的使用

标签:out   color   ide   密码   bin   lap   closed   write   iges   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!