module sys module (and interpreter related modules)
Module import module:
import sys
sys.path.append("D:");
for i in sys.path:
print(i)
The os module of the module (the module related to the system)
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)
Very important
ask.com
biying.com
stackoverflow.com
Secure MD5 encryption
import hashlib
ha=hashlib.md5(bytes('123',encoding='utf-8'))
ha.update(bytes('123',encoding='utf-8'))
print(ha.hexdigest())
#The following is an example of MD5 actual application login
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': pwd=input('Password:')
name=input('Username:')
register(name,pwd)
if i=='1':
name = input('username:')
pwd = input('password:')
t=login(name,pwd)
if t==True:
print(" Login successful")
else:
print("Login failed")
#end