Python3 os模块&sys模块&hashlib模块

 1 '''
 2 os模块
 3 非常重要的模块
 4 '''
 5 import os
 6 # print(os.getcwd())      # 获取当前工作目录
 7 # os.chdir(r'路径名')      # 改变当前工作目录
 8 # print(os.curdir)        # 返回当前目录,'.'
 9 # print(os.pardir)        # 获取当前目录的父目录名(字符串),'..'
10 # os.makedirs('.ssssss')    # 生成文件夹,递归生成(本人使用的是Windows)
11 # os.removedirs('.ssssss')      # 删除文件夹,只能删除空文件夹(本人使用的是Windows)
12 # os.mkdir('bob')         # 生成文件夹,不能递归生成
13 # os.rmdir('.\bob')       # 删除文件夹,不能递归
14 # print(os.listdir(r'绝对路径'))          # 列出此路径下的文件夹和文件
15 # os.remove('')       # 删除某一文件,不能删除文件夹
16 # os.rename('原来的名字','新的名字')     # 重命名,类似于Linux中的mv命令
17 # os.stat('文件绝对路径')  # 获取文件/目录信息
18 # os.sep    # 输出操作系统特定的路径分隔符,win下为"\",Linux下为"/"
19 # os.linesep   # 输出当前平台使用的行终止符,win下为"	
",Linux下为"
"
20 # os.pathsep    # 输出用于分割文件路径的字符串
21 # print(os.name)    # 输出字符串指示当前使用平台。win显示'nt'; Linux显示'posix'
22 # os.system("bash command")  # 运行shell命令,直接显示
23 # os.environ  # 获取系统环境变量
24 # os.path.abspath('路径')  # 返回path规范化的绝对路径
25 # os.path.split('路径')  # 将path分割成目录和文件名二元组返回
26 # os.path.dirname('路径')  # 返回path的目录。其实就是os.path.split(path)的第一个元素
27 # os.path.basename('路径')  # 返回path最后的文件名。如何path以/或结尾,那么就会返回空值。即os.path.split(path)的第二个元素
28 # os.path.exists('路径')  # 如果path存在,返回True;如果path不存在,返回False
29 # os.path.isabs('路径')  # 如果path是绝对路径,返回True
30 # os.path.isfile('路径')  # 如果path是一个存在的文件,返回True。否则返回False
31 # os.path.isdir('路径')  # 如果path是一个存在的目录,则返回True。否则返回False
32 # os.path.join([ '路径1','路径2',...])  # 将多个路径组合后返回,第一个绝对路径之前的参数将被忽略
33 # os.path.getatime('路径')  # 返回path所指向的文件或者目录的最后存取时间
34 # os.path.getmtime('路径')  # 返回path所指向的文件或者目录的最后修改时间
35 
36 
37 
38 '''
39 sys模块
40 Python解释器进行交互
41 '''
42 
43 import sys
44 # print(sys.argv)           # 命令行参数List,第一个元素是程序本身路径
45 # sys.exit(0)        # 退出程序,正常退出时exit(0),1-127都是有错误的
46 # print(sys.version)        # 获取Python解释程序的版本信息
47 # print(sys.maxint)         # 最大的Int值
48 # print(sys.path)           # 搜索模块路径,初始化时使用PYTHONPATH环境变量的值
49 # print(sys.platform)       # 显示目前操作系统平台名称
50 
51 
52 '''
53 hashlib模块
54 将明文转换成密文(加密)
55 '''
56 
57 import hashlib
58 # md5
59 # c1 = hashlib.md5()
60 # print(c1)
61 # 
62 # c1.update('Welcome to china'.encode('utf-8'))   # 编码转换为utf-8,Python3中 字符串是Unicode,Python3 默认是utf-8编码
63 #                                                   # 更新c1 的内容
64 # print(c1.hexdigest())       # 通过十六进制取值
65 # c1.update('bob'.encode('utf-8'))
66 # print(c1.hexdigest())       # 新的密文
67 # 
68 # c2 = hashlib.md5()
69 # c2.update('Yeah'.encode('utf-8'))
70 # print(c2.hexdigest())
71 
72 
73 # sha
74 # c3 = hashlib.sha256()      # 256一般用的比较多
75 # c3.update('ads'.encode('utf-8'))
76 # print(c3.hexdigest())
原文地址:https://www.cnblogs.com/Infi-chu/p/7687520.html