import sysimport osprint(sys.platform) #判断操作系统,windows10输出win32print("sys.path:",sys.path) #返回模块的搜索路径,初始化时使用PYTHONPATH环境变量的值(python的安装路径),注意:不是指操作系统的环境变量sys.path.append(r'E:\syz\ly-code\day5')sys.path.insert(0,r'E:\syz\ly-code\day5')print("sys.argv:",sys.argv) #用来获取命令行里面运行python文件的时候传入的参数#sys.exit(n) #退出程序,正常退出时exit(0)print(sys.version) #获取Python解释器的版本信息sys.stdout.write('please:') # 向屏幕输出一句话# val = sys.stdin.readline()[:-1] # 获取输入的值# print(val)print(sys.getdefaultencoding())#获取系统默认的编码print("=================编码格式===================")str = "菜鸟教程";str_utf8 = str.encode("UTF-8")str_gbk = str.encode("GBK")print(type(str_utf8),type(str_gbk))#encode()后,返回的是一个bytes类型print("UTF-8 编码:", str_utf8)print("GBK 编码:", str_gbk)print("UTF-8 解码:", str_utf8.decode('UTF-8','strict'))print("GBK 解码:", str_gbk.decode('GBK','strict'))import hashlibprint("===================md5加密=================")m = hashlib.md5()passwd = 'beautiful'print("encode:",passwd.encode())print("加密update:",m.update(passwd.encode()))#不能直接对字符串加密,要先把字符串转成bytes类型,update()返回一个Noneprint(m.hexdigest())#hexdigest()返回一个字符串m = hashlib.md5()m.update(b"Hello")m.update(b"It's me")print(m.digest())m.update(b"It's been a long time since last time we ...")print(len(m.digest()),m.digest()) # 2进制格式hash,16位print(len(m.hexdigest()),m.hexdigest()) # 16进制格式hash,32位print("===============hashlib.sha1()加密===============")hash = hashlib.sha1()hash.update(b'admin')print(hash.hexdigest())print("===============hashlib.sha256()加密============")hash = hashlib.sha256()hash.update(b'admin')print(hash.hexdigest())print("==============hashlib.sha384()加密=============")hash = hashlib.sha384()hash.update(b'admin')print(hash.hexdigest())print("=============hashlib.sha512()加密=============")hash = hashlib.sha512()hash.update(b'admin')print(hash.hexdigest())
转载于:https://www.cnblogs.com/mtszw/p/9022061.html
转载请注明原文地址: https://mac.8miu.com/read-15772.html