python 开发工具库资料合集
Posted 帅气的黑桃J
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 开发工具库资料合集相关的知识,希望对你有一定的参考价值。
1.Introduction
record some common command
2.grammar
doc:
lambda
import time
# 1.变量转变为函数
ans = lambda x,y : x+y
print(ans(1,3))
# 2.覆盖其他函数的功能
time.sleep=lambda x:None
# 输出无效
time.sleep(3)
# switch的使用
def switch(options):
funcdic =
1: lambda: method1(),
2: lambda: method2(),
3: lambda: method3(),
return funcdic[options]()
3. Anaconda
doc:
4.File & os
doc:
4.1 os file operate
import os
# 返回当前目录
os.getcwd()
# 返回上一级目录地址
os.path.abspath(os.path.join(os.getcwd(), '..'))
5. Crawler(request+beautifulsoup)
doc:
5.1 A easy request Demo
import requests
base_url = 'https://www.baidu.com/more/'
response = requests.get(base_url)
response.encoding='utf-8'
print(response.text)
5.2 Beautiful soup demo1
from bs4 import BeautifulSoup
import requests
base_url = 'https://www.shanghairanking.cn/rankings/bcur/2022'
if __name__ == '__main__':
print('[info] start')
response = requests.get(base_url)
response.encoding='utf-8'
# get soup
soup = BeautifulSoup(response.text,'lxml')
# get rank info of one page
uni_html_info_list = soup.find('table').find('tbody').find_all('tr')
cols = "0:6^10\\t1:6^10\\t2:6^10\\t3:6^10\\t4:^10\\t5:^10\\t"
print(cols.format('排名', '大学名称', '省市', '类型', '总分', '办学层次', chr(12288)))
# analysis every uni info
for uni_item_html_info in uni_html_info_list:
uni_item_info = []
uni_item_info.append(uni_item_html_info.find_all('td')[0].find('div').string.strip())
uni_item_info.append(uni_item_html_info.find_all('td')[1].find_all('a')[0].string)
uni_item_info.append(uni_item_html_info.find_all('td')[2].contents[0].strip())
uni_item_info.append(uni_item_html_info.find_all('td')[3].contents[0].strip())
uni_item_info.append(uni_item_html_info.find_all('td')[4].contents[0].strip())
uni_item_info.append(uni_item_html_info.find_all('td')[5].contents[0].strip())
print(cols.format(uni_item_info[0],uni_item_info[1],uni_item_info[2],uni_item_info[3],uni_item_info[4],uni_item_info[5],chr(12288)))
print('[info] end')
5.3 Beautiful soup demo2
from bs4 import BeautifulSoup
import requests
base_url = 'https://www.cae.cn'
home_url = '/cae/html/main/col48/column_48_1.html'
if __name__ == '__main__':
print('[info] start')
response = requests.get(base_url+home_url)
response.encoding='utf-8'
# get soup
soup = BeautifulSoup(response.text,'lxml')
# get every ys info url
for item_list in soup.find_all(name='div', attrs='class': 'ysxx_namelist clearfix'):
for item in item_list.find_all('a'):
# ys_name = item.string
item_url = item.get('href')
item_response = requests.get(base_url+item_url)
item_soup = BeautifulSoup(item_response.text,'lxml')
ys_description = ''
for item_p in item_soup.find(name='div',attrs='class': 'intro').find_all('p'):
ys_description = ys_description + item_p.string.strip()
with open("ys_description.txt", "a+",encoding='utf-8') as f: # 打开文件
f.write(ys_description+'\\n') # 读取文件
f.close()
print(ys_description)
6. Django
learning info:
7. pymysql
doc:
8.JSON
doc:
-
dumps(obj covert json)
import json
# dumps可以格式化所有的基本数据类型为字符串
data1 = json.dumps([]) # 列表
print(data1, type(data1))
data2 = json.dumps(2) # 数字
print(data2, type(data2))
data3 = json.dumps('3') # 字符串
print(data3, type(data3))
dict = "name": "Tom", "age": 23 # 字典
data4 = json.dumps(dict)
print(data4, type(data4))
# 将dict中的数据写入文件中
with open("test.json", "w", encoding='utf-8') as f:
# indent 超级好用,格式化保存字典,默认为None,小于0为零个空格
f.write(json.dumps(dict, indent=4))
json.dump(dict, f, indent=4) # 传入文件描述符,和dumps一样的结果
- loads(str covert to json)
import json
dict = '"name": "Tom", "age": 23' # 将字符串还原为dict
data1 = json.loads(dict)
print(data1, type(data1))
with open("test.json", "r", encoding='utf-8') as f:
data2 = json.loads(f.read()) # load的传入参数为字符串类型
print(data2, type(data2))
f.seek(0) # 将文件游标移动到文件开头位置
data3 = json.load(f)
print(data3, type(data3))
9.pyqt
doc:
QMessageBox.about(self, "提示", "需要选中一项内容")
user = self.lineEdit_user.text()
10.re
doc:
11.numpy
doc:
11.1 numpy file operate
import numpy as np
a = np.random.rand(2, 3)
print(a)
# save as npy
np.save('my_array', a)
# read from npy
a_loaded = np.load('my_array.npy')
print(a_loaded)
# save as
np.savetxt('my_array.csv', a, delimiter=',')
a_loaded = np.loadtxt('my_array.csv', delimiter=',')
print(a_loaded)
12.pandas
doc:
13.Thread
doc:
14.socket
doc:
15.Tools
15.1 pyinstaller
doc:
16.Pypi
doc:
17.design mode
doc:
以上是关于python 开发工具库资料合集的主要内容,如果未能解决你的问题,请参考以下文章
Windows操作系统+朝鲜红星+国产麒麟+红旗+渗透专用系统+Oracle专用+技术专栏资源大合集 | 寻找C站宝藏
Windows操作系统+朝鲜红星+国产麒麟+红旗+渗透专用系统+Oracle专用+技术专栏资源大合集 | 寻找C站宝藏