PyTools
Cute Tools By Python
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
000.The Zen Of Python, Python之禅
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
001.Test_CleanBigFile, 大文件扫描
002.Test_Proxy, 端口映射之代理服务器
003.Test_Telnet, 循环telnet
004.Test_Json, Json解析 /*json.tool*/
005.Test_SocketServer, Socket5代理服务器[爬虫]
006.Test_pandas_func, pandas列函数
007.Test_count_XXX_in_string, 用于计算给定字符串中是否有连续出现n次的字符
008.Test_pandas_query, pandas-query筛选
009.Test_multiprocessing_run, multiprocessing多线程
010.Test_pymysql_pools, mysql数据库连接池 by pymysql
011.Test_requests&requests_futures, requests连接优化及堵塞问题
012.Test_py_memory, python代码内存检查
013.Test_DecisionTreeClassifier_var, py决策树 # TODO: bug!!!
014.Test_CardBinCheck, 支付宝卡号验证工具
015.Test_F1-micro&F1-macro, sklearn metrics F1
016.Notice_use_jupyter, jupyter使用提醒
017.Model_build_GridSearchCV, GridSearchCV
018.Test_rotate_image, 矩阵转换
019.Some_By_30-seconds, 30秒代码学习摘要
020.pandas_groupby&merge, pandas -Groupby; -Merge
021.pandas_datetime_mon, pandas Datetime
022.Py_SimpleHTTPServer, PyModule For The HTTPServer
023.Notice_python, Python坑
024.SqrtCal, 快速平方
025.What_is_python3.8.md, Python3.8一览
026.Py2Pyc2Pyo, Py转换Pyc/Pyo/So文件
027.PyDataMemory, Py数据内存
028.Py2EXE, Py转EXE
029.Test_gevent_requests.py, gevent/requests
030.Be_Pythonic, Pythonic
031.Test_TimeCal, TimeCal TODO:
032.Test_Mrjob_MapReduce, Mrjob To MapReduce
033.Print_Logging, logging 日志
034.Test_bin_ascii, 编码转换bin&ascii
035.Pycharm_Instructions, Pycharm使用说明201801 SSH
036.PyCrawler_Spiget, 爬虫IP、代理
037.The_list_of_pandas, pandas
038.Test_PyClass, Class类
039.Test_qiskit_QuantumCal, IBM qiskit 量子计算
040.WxpythonDemo, Wxpython GUI
041.Test_Pygame, pygame for game GUI
042.Test_putZ8inpy, 实现 PUT("787",Z8.) > "00000787"
043.Test_Read_npy, npy读取
044.Easy_in_list, list类
045.Test_HDF5, HDF5文件
046.Test_tqdm, 进度条 Nice
047.Test_ImageAI, 图像内容预测、对象预测
048.Test_Py_DFROW, pandas DF 取下一行数
049.TestWget, 简单爬虫
050.TestTF_Data_MNIST, TensorFlow MNIST数据重新下载
051.Test_pyfunc, 测试py函数 时间-内存
052.Test_ROC_AUC, 测试ROC、AUC
053.Test_DiffMatch, 差异化匹配
054.Test_Feature_selection, 变量挑选
055.Test_Latitude_longitude, 经纬度距离计算
056.Test_MyQR, 生成二维码
057.Test_wget, wget下载链接
058.wordcloud, 词云
059.Test_watch_fits, fits天文数据读取
060.Test_Plot_waterfall, Plot瀑布图
061.Test_selenium_WebAuto, 基于selenium网页自动化
062.Test_list_pickle_gzip, list导pickle并gzip压缩
063.Test_pandas_datetime, 时间计算
064.Test_continue_break_pass, continue\break\pass语法理解
065.Test_cluster, 聚类
066.Test_Kalman_filtering, 卡尔曼滤波算法
067.Test_numpy_c_r_m, numpy矩阵c_/r_/扁平化转换
068.Test_gc, python垃圾回收机制
069.Test_scipy_sparse, 稀疏矩阵库scipy.sparse
070.YAPF_PEP8, Python代码规范
071.Test_faker_TestDemo, faker库造测试案例
072.PythonDevLevel, 阿里云大学-Python测试
073.TOpencv, CV计算机视觉-00.Opencv入门
~~Please Wait For Next!!!~~
Sample1:
# 003.Test_Telnet, 循环telnet
import time
import random
import telnetlib
h, p, n = "0.0.0.0", 11111, 0
while True:
time.sleep(random.randrange(0, 1000)/1000)
n += 1
try:
tb = telnetlib.Telnet()
tb.open(host=h, port=p, timeout=1)
print("Step %5d" %n, tb.read_very_eager().decode(), "-"*20)
tb.close()
except Exception as e:
print("Fail %5d" % n, e)
Sample2:
# 033.Print_Logging, logging 日志
def log_test01():
import logging
import logging.handlers
LOG_FILE = "033.Print_Logging.log"
handler = logging.handlers.RotatingFileHandler(LOG_FILE, maxBytes=20*1024*1024, backupCount=10) # 实例化handler
fmt = "%(asctime)s - %(name)s - %(levelname)s - %(message)s - [%(filename)s:%(lineno)s]"
formatter = logging.Formatter(fmt) # 实例化formatter
handler.setFormatter(formatter) # 为handler添加formatter
logger = logging.getLogger('xzs') # 获取名为xzs的logger
logger.addHandler(handler) # 为logger添加handler
logger.setLevel(logging.DEBUG)
logger.debug("Hello boy, Debug")
logger.info("Hello boy, Info")
2019-10-23 20:16:36,248 - xzs - DEBUG - Hello boy, Debug - [033.Print_Logging.py:18]
2019-10-23 20:16:36,248 - xzs - INFO - Hello boy, Info - [033.Print_Logging.py:19]
Sample3:
# 060.Test_Plot_waterfall, Plot瀑布图
import matplotlib.pyplot as plt
lr0, lr1, lr2 = 76234, 53654, 46857
print(lr0, lr1, lr2)
plt.figure(figsize=(16, 8))
plt.bar(
[0, 1, 2, 3],
[lr0, lr0-lr1, lr1-lr2, lr2],
color="#87CEFA",
width=0.4,
bottom=[0, lr1, lr2, 0],
)
plt.savefig("060.Test_Plot_waterfall.jpg")
plt.show()
详见链接。
相关链接,求Star!!!
https://github.com/IvanaXu/PyTools
https://www.yuque.com/ivanaxu/pytools