常用标准库模块

#!/usr/bin/env python3
# _ * _ coding:utf-8 _*_
# Date: 2019/8/5 14:32
# Author:BY
# Version:1.0

# 复习re模块#
"""
import re
string = "by:123434:man:13023210321"
# res_obj = re. compile("\d+\w")
res_obj = re.compile("^\d{3}$")
print(res_obj.findall(string))  # 列表,查找数据
result = res_obj.match("1234")  # 一般用来验证数据,注意开头和结尾,match以第一个开头
re.search()      # 查找,只会找到第一组符合条件的数据
re.sub("正则","新字符串","被替换的数据")
re.split()  # 根据规则分割数据
print(result.group()if result else "数据验证失败")
"""

# 复习 sys模块 #  (sys 模块代表了 Python 解释器,主要用于获取和 Python 解释器相关的信息)
# import sys
# # print(sys.version)
# # print(sys.version_info[2])
# print(sys.path)  # 查看当前使用的解释器可以调用的模块地址
# print(sys.path.append()) # 把自己的模块位置引入当前
# print(sys.argv)  # 获取第三方参数
# sys.exit() # 执行此命令 直接退出程序



# 复习 random (随机数模块) #
# import random
# print(random.random())
# print(random.randint(1,100)) # 1-100 内随机生成数字
# print(random.randrange(1,10,3)) # 1-10 步长为3
# print(random.choices(["a","b","c","d"]))


# 复习  hashlib  #
# import hashlib
# md5 = hashlib.md5('a'.encode()) # 使用md5 格式加密 其他加密方法有(sha系列,byt64等)
# print(md5.hexdigest())
# 一个加密函数
# def md5_password(msg):
#     md5 = hashlib.md5(bytes(msg,encoding="utf-8"))
#     return md5.hexdigest()
# print(md5_password((md5_password("123"))))


# 复习 json #
# 序列化和反序列化
# object ->  序列化
# str -> 反序列化
# import json
# dic = { "name":11,
#         "age":12
#                   }
# with open("my.json","w",encoding="utf-8")as f:


## import pickle #  和json差不多 ¥¥

## os 模块  ## 方法很多,和系统相关 (python使用操作系统的模块)
import os
from os import path
# dir 查看包含的模块
# print(dir(os))
# os.system("shutdown -s") # 调用window系统命令
# print(os.listdir(r"D:\\")) # 将目录中的文件放入列表中
# print(os.sep)   # 当前系统的分割符
# print(os.linesep) # 当前系统的换行符
# print(os.getcwd())  # 获取当前的工作目录

# def os_demo():
#     dirs = os.popen("dir").read(r"D:\\")
#     print(dirs)
#     dirs_info = os.scandir()
#     for info in dirs_info:
#         print("文件夹: {},路径:{}, inode: {},文件夹 {},文件?{},链接?{}".format(info.name,
#              info.path, info.inode(),info.is_dir(),info.is_file(), info.is_symlink()))
#         stats = info.stat()
#         print(">>> 访问时间:{}, 修改时间:{}, 模式修改时间:{},大小: {}".format(stats.st_atime,
#         start.st_ctime,stats.st_atime,stats.st_size))
# import signal
# paths = [r'file.txt', r"/python/lib/hello.py", r"/python/local/text.txt", "C:/python/local", "C:/python/file.txt"]
# strs = os.path.abspath(paths[0])
# strs1 = os.path.abspath(paths[1])
# strs2= os.path.abspath(paths[2])
# strs3 = os.path.abspath(paths[3])
# print(strs)
# print(strs1)
# print(strs2)
# print(strs3)



# import random
# def qiu_qiu():
#     one = random.randint(1, 33)
#     one1 = random.randint(1, 33)
#     one2 = random.randint(1, 33)
#     one3 = random.randint(1, 33)
#     one4 = random.randint(1, 33)
#     one5 = random.randint(1, 33)
#     one7 = random.randint(1, 16)
#     if one != one1 != one2 != one3 != one4 != one5:
#         lis = [one, one1, one2, one3, one4, one5]
#         s = sorted(lis)
#         lis_1 = [s,one7]
#     else:
#         qiu_qiu()
#     return lis_1
#
#
# print(qiu_qiu())

你可能感兴趣的:(理论笔记)