![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python学习
Leowner
以德报怨,何以报德?。。
展开
-
Python open 默认编码修改
如果在Windows平台使用python,很多时候open函数的默认编码方式为gbk,如果自行编码,可以通过encoding参数来修改为utf-8,但当执行其他人合作完成的代码时,要修改每一个open的参数成本过高。解决方法:在运行命令行时,在python.exe 和 程序名.py 之间加入 -X utf8即可Pycharm可以选择edit Configurations,在Interpret...原创 2020-03-22 11:23:21 · 3888 阅读 · 2 评论 -
python网络爬虫批量获取百度百科词条 使用request和beautifulsoup
理论上可以直接批量处理百度百科词条,但是存在如下问题:百度百科需要比较严格的输入搜索名称,模糊搜索能力不强百度百科在不输入词条后面的id时,请求频率太高会弹出error百度百科可能会弹出一词多义选择,需要额外处理。因此,选择直接使用百度搜索,利用搜索向百度百科进行跳转。按照常理来讲,可以直接在搜索结果中检索所有标题,再用正则表达式判断网址中是否包含baike。实际上,由于baidu...原创 2020-02-22 23:17:25 · 1104 阅读 · 0 评论 -
paddlepaddle 波士顿房价预测demo
paddlepaddle中的dataset已经预置了波士顿房价的数据值,本demo仅测试了paddlepaddle的基本框架。参考官方aistudio后,train代码如下:import paddleimport paddle.fluid as fluidimport numpy as npimport osimport matplotlib.pyplot as pltBUF_SI...原创 2020-02-15 11:04:16 · 549 阅读 · 0 评论 -
python request批量爬虫模板2
import requestsimport timeheaders = { 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'}f2 = open("test.csv",...原创 2020-02-09 20:18:21 · 221 阅读 · 0 评论 -
python matplotlib学习笔记
import matplotlib.pyplot as pltplt.plot([0, 2, 4, 6, 8], [3, 1, 4, 5, 2]) # 前半部分为x值,后半部分为y值plt.ylabel("grade")plt.axis([-10, 10, 0, 7]) # 设置x轴和y轴的尺度# plt.show() # 显示pl...原创 2020-02-06 10:31:30 · 235 阅读 · 0 评论 -
request爬虫基础模板
爬取内容为百度百科,保存在同目录的1.html下,更改了headers作为隐藏import requestsfrom bs4 import BeautifulSoupheaders = { 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Ch...原创 2020-01-30 10:48:26 · 296 阅读 · 0 评论 -
Python实现批量pandoc 将markdown md文件 转换为其他doc epub mobi html文件
import osdef get_file_name(file_dir): for root, dirs, files in os.walk(file_dir): # print(root) # print(dirs) # print(files) for file in files: if os...原创 2019-08-21 21:45:28 · 1853 阅读 · 0 评论 -
Python学习笔记3
print() 函数也可以接受多个字符串,用逗号“,”隔开,就可以连成一串输出:print()会依次打印每个字符串,遇到逗号“,”会输出一个空格,因此,输出的字符串是这样拼起来的:>>> print('The quick brown fox', 'jumps over', 'the lazy dog')The quick brown fox jumps over the l...原创 2018-10-17 13:47:17 · 662 阅读 · 0 评论 -
python实现文本进度条
基本:import timescale = 10print("{:-^20}".format("执行开始"))for i in range(scale + 1) : a = '*' * i b = '.' * (scale - i) c = (i / scale) * 100 print("{:^3.0f}%[{}->{}]".format(c, a, b)) tim...原创 2018-10-03 11:17:43 · 1158 阅读 · 0 评论 -
Python学习笔记2
字符串2使用.format()方法可以对字符串进行格式化处理。使用time库以解决和时间有关的问题 vscode中可以使用shift+enter来运行当前行,使用ctrl+F5来运行整个程序 使用pyinstaller可以对py文件进行打包 字符串.center()方法,可以快速的将字符串居中并在两侧加入其他字符以填充...原创 2018-10-03 21:30:51 · 111 阅读 · 0 评论 -
Python学习手记1
字符串单行字符串直接用单引号或者双引号括住,多行字符串用三个单引号或者三个双引号表示,可以当作注释使用如果字符串中出现双引号,字符串要用双引号括住如果既需要双引号又需要双引号,可以使用三引号括起来字符串使用从0到正数的从前标识 以及 从-1到负数的从后标识字符串可以使用 <字符串>[M] ,M为正向或反向索引,来获取单个字符,或者&amp原创 2018-10-01 15:09:44 · 150 阅读 · 0 评论