Python中小知识点汇总(常期更新)

1.a、a+、r+、w+区别

https://blog.csdn.net/ztf312/article/details/47259805

w新建只写,w+新建读写,二者都会将文件内容清零

(以w方式打开,不能读出。w+可读写)

w+与r+区别:

r+:可读可写,若文件不存在,报错;w+: 可读可写,若文件不存在,创建

a附加写方式打开,不可读;a+: 附加读写方式打开)

2. python 中的main

https://www.cnblogs.com/lvxiuquan/archive/2012/07/09/2582437.html

3.sys.stdout.flush() 刷新输出

https://blog.csdn.net/qq_20603001/article/details/62887099

可以用在网络程序中多线程程序,多个线程后台运行,同时要能在屏幕上实时看到输出信息。

4.异常相关的介绍

http://www.runoob.com/python/python-exceptions.html

5.logging模块

https://www.jianshu.com/p/feb86c06c4f4

6.Python 中得到当前日期的前|后几天

7. 字符串格式化

http://www.cnblogs.com/vamei/archive/2013/03/12/2954938.html

8.列表的extend方法

http://www.runoob.com/python/att-list-extend.html

extend() 函数用于在列表末尾一次性追加另一个序列中的多个值(用新列表扩展原来的列表)。

列表的reverse方法,用于反向列表中元素。

http://www.runoob.com/python/att-list-reverse.html

9.类class中_init_函数以及参数self

https://blog.csdn.net/LY_ysys629/article/details/54893185

10.文件I/O系统

http://www.runoob.com/python/python-files-io.html

11.编码和解码

https://www.cnblogs.com/linjiqin/p/3674825.html

很多莫名其妙的问题,最后都是编码问题,所以首先check编码和解码。

12. time 和 datetime的区别和联系

http://gracece.com/2014/10/the-distinction-between-date-and-datetime-in-python/

http://www.wklken.me/posts/2015/03/03/python-base-datetime.html#datetime-timetuple

13.python2.7中的urllib和urllib2的学习

https://www.cnblogs.com/wly923/archive/2013/05/07/3057122.html

http://zhuoqiang.me/python-urllib2-usage.html

常用的就是 urllib2.urlopen(url, timeout=100)

14. 在使用urllib2.urlopen(url).read()时没有设置超时时间,导致不返回结果,程序卡死了。

解决方法:设置retry

参考:https://www.168seo.cn/python/23889.html

timeout中的时间单位为秒。

第二种要安装retry库,亲测没有第一种好用:

猜你喜欢

转载自blog.csdn.net/baidu_33718858/article/details/81455512