review
package
A module aaa.py too many methods, it is divided into multiple files m1.py, m2.py, and m2.py into the m1.py named aaa package (init file containing the folder called packets) in
Import aaa init packet is introduced, the addition of a conventional init which f1 ()
import aaa
aaa.f1()
import aaa
aaa.f1()
# aaa/init.py
from aaa.m1 import f1
Search path to the executable file prevail, also said that the executable file to find someone who can run, init can only find someone who
Relative path: to break this rule search path, the search path is not required to execute documents shall prevail
.
It represents the current path..
It represents a layer
Absolute path: the path of death write
time module
Print three kinds of time in different formats
time.time() # 打印当前时间(秒)
time.sleep() # 睡眠
datetime module
Change the time
datetime.datetime.now() + datetime.timedelta(3)
hashlib module
encryption
m = hashlib.md5()
m.update(b'hello')
m.update(b'hello')
print(m.hexdigest())
m = hashlib.md5()
m.update(b'hellohello')
print(m.hexdigest())
- Results are always the same length of the string
- Superposition
hmac module
Encryption, salt processing
m = hmac.new(b'123')
m.update(b'hellow')
print(m.hexdigest())
json module
- Sequence of: the type of data stored into the python json string
- Deserialization: json string read into the data type python
Cross-platform
dict/list
dic = {'a':1}
# 内存中转化
data = json.dumps(dic)
data = json.loads(data)
# 文件中转化
with open() as fw:
json.dump(dic, fw)
with open() as fr:
data = json.load(fr)
pickle module
We can not be cross-platform, but supports all data types python
dic = {'a':1}
# 内存中转化
data = pickle.dumps(dic)
data = pickle.loads(data)
# 文件中转化
with open() as fw:
pickle.dump(dic, fw)
with open() as fr:
pickle = json.load(fr)
os module
And to interact with the operating system
os.path.join() # 拼接地址
os.path.listdir() # 列出文件夹内的所有文件
os.path.dirname() # 获取上一级目录
os.path.abspath() # 获取文件的绝对路径
os.path.exists() # 文件是否存在
sys module
And to interact with python interpreter
sys.argv # 用cmd执行python文件的时候获取参数
sys.path # 获取环境变量
logging module
import logging
# 1. 生成logger对象
logger = logging.getLogger('nick')
logger1 = logging.getLogger('jason')
# 2. 格式
formmater1 = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s -%(module)s: %(message)s',datefmt='%Y-%m-%d %H:%M:%S %p',)
formmater2 = logging.Formatter('%(asctime)s : %(message)s',datefmt='%Y-%m-%d %H:%M:%S %p',)
formmater3 = logging.Formatter('%(name)s %(message)s',)
# 3. 打印对象
h1 = logging.FileHandler('h1.log')
sm = logging.StreamHandler()
# 4. 打印对象绑定格式
h1.setFormatter(formmater1)
sm.setFormatter(formmater2)
# 5. logger绑定打印对象
logger.addHandler(h1)
logger.addHandler(sm)
# 6. 设置级别
logger.setLevel(50)
logger.debug('debug')
logger.info('info')
logger.warning('warning')
logger.error('error')
logger.critical('critical')
numpy module
Operation numpy array (matrix), scientific computing, tensorflow
pandas module
File (excel) processing
read_excel()/to_excel()
matplotlib module
画图, plt.plot () / plt.bar () / plt.scatter () / plt.hist () / plt.pie ()