码迷,mamicode.com
首页 > 编程语言 > 详细

python模块

时间:2018-04-28 21:06:17      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:os模块   enc   file   exist   close   path   byte   实例   pre   

模块sys模块(和解释器相关的模块)

模块之导入模块:

        import sys

        sys.path.append("D:");

        for i in sys.path:

              print(i)

 

模块之os模块(和系统相关的模块)

import os
str1=‘D:‘
str2=‘home‘
str3=‘index‘
t=os.path.join(str1,str2,str3)
print(t)

os.stat(‘path/filename‘)
os.path.dirname(path)
os.path.exists(path)
os.path.join(path1,path2,path3)

 很重要

ask.com

biying.com

stackoverflow.com

 安全的MD5加密

import hashlib

ha=hashlib.md5(bytes(‘123‘,encoding=‘utf-8‘))

ha.update(bytes(‘123‘,encoding=‘utf-8‘))
print(ha.hexdigest())


#下面是MD5实际应用登录的实例
import hashlib
def register(user,pwd):
with open(‘haha‘,‘w‘,encoding=‘utf-8‘) as f:
f.write(user+‘|‘+md5(pwd))
f.close()
def login(name,pwd):
with open(‘haha‘,‘r‘,encoding=‘utf-8‘) as f:
for line in f:
c,d=line.strip().split(‘|‘)
if c==name and d==md5(pwd):
return True
else:
return False
def md5(pwd):
ha=hashlib.md5(bytes(‘guozhendong‘,encoding=‘utf-8‘))
ha.update(bytes(pwd,encoding=‘utf-8‘))
return ha.hexdigest()
i=input("1.登录;2.注册")
if i==‘2‘:
name=input(‘用户名:‘)
pwd=input(‘密码:‘)
register(name,pwd)
if i==‘1‘:
name = input(‘用户名:‘)
pwd = input(‘密码:‘)
t=login(name,pwd)
if t==True:
print("登录成功")
else:
print("登录失败")



#end



python模块

标签:os模块   enc   file   exist   close   path   byte   实例   pre   

原文地址:https://www.cnblogs.com/guozhendong/p/8950328.html

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