- 博客(19)
- 收藏
- 关注
原创 TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
pip install 包报错:TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'解决:·TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'·sudo apt-get install python-pip
2018-02-01 12:02:23 5994
原创 Python swapcase()
Python swapcase() 方法用于对字符串的大小写字母进行转换。swapcase()方法语法:str.swapcase();
2017-12-18 17:09:01 1360
转载 转换编码 u'```'
>>> s = u'\xb3\xc2\xbd\xa8\xc3\xf4'>>> s.encode('raw_unicode_escape')
2017-12-05 18:02:33 419
原创 记录redis MD5数据库入库去重
记录下mysql 入库去重:import hashlib, redisred = redis.Redis(host="118.26.185.188", port=6379)mdkey = hashlib.md5()mdkey.update(a+b+c+d+g+i)zhujian = mdkey.hexdigest()if not self.red.get(zhujian):
2017-08-10 15:43:49 917
转载 转载ubuntu安装Scrapy
Scrapy是Python开发的一个快速,高层次的屏幕抓取和web抓取框架,用于抓取web站点并从页面中提取结构化的数据。Scrapy用途广泛,可以用于数据挖掘、监测和自动化测试。 官网网站http://www.scrapy.org/1、安装如下软件sudo apt-get install build-essential;sudo apt-get install
2017-06-30 11:18:48 390
原创 使用scrapy爬取CR糗百图片
记录一下使用SCRAPY爬取糗百图片1.创建项目:使用命令行提示符输入:scrapy startproject tupian www.chengrenqiubai.com2.打开项目目录,编辑items文件,内容:import scrapyclass TupianItem(scrapy.Item): # define the fields for your it
2017-06-25 14:38:07 799
原创 Python count()
Python count() 方法用于统计字符串里某个字符出现的次数。可选参数为在字符串搜索的开始与结束位置。count()方法语法:str.count(sub, start= 0,end=len(string))sub -- 搜索的子字符串start -- 字符串开始搜索的位置。默认为第一个字符,第一个字符索引值为0。end -- 字符串中结束搜索的位置。字符中第一个字符的索
2017-05-08 11:30:29 504
原创 Python replace()
replace 是将字符串old替换为newstr.replace(old, new[, max])>>> a = 'sdfaf,sda,f,dsaf,asd,f,sadf,'>>> a.replace(',','')'sdfafsdafdsafasdfsadf'max为替换不超过max次数>>> a.replace('sd','77',2)'77faf,77a
2017-05-05 13:55:07 727
原创 Python case str[::-1]
Instructions:Reverse every other word in a given string, then return it. Don't forget to include the spaces!def test(s): rr = [] a = s.split(' ') for i in a : # if i 角标为偶数
2017-04-27 10:14:38 908
原创 Python isinstance
记录isinstance 例子一个:给出列表,输出整数部分列表例子:def filter_list(l): a = l c = [] for x in a: if isinstance(x,int)==True: c.append(x) return cisinstance 用来判断数据类型
2017-04-26 12:48:24 291
原创 Python 错误处理
当我们认为某些代码可能会出错时,就可以用try来运行这段代码,如果执行出错,则后续代码不会继续执行,而是直接跳转至错误处理代码,即except语句块,执行完except后,如果有finally语句块,则执行finally语句块,至此,执行完毕。例:>>> a = bTraceback (most recent call last): File "", line 1, in
2017-04-22 14:11:23 461
原创 Python 菲波那切数列
菲波那契数列指的是这样一个数列:1,1,2,3,5,8,13,21 ,34,55 , 89 , 144 ……这个数列从第三项开始,每一项都等于前两项之和例:def feb(max): n,a,b = 0,0,1 L = [] while n L.append(b) a,b = b,a+b
2017-04-22 13:52:34 1823
原创 Python assert 用法
Python中assert用来判断语句的真假,如果为假的话将触发AssertionError错误python help document的解释:Assert statements are a convenient way to insert debugging assertions into a program:例:>>> a = 3>>> assert a ==3>>>
2017-04-20 21:54:55 463
原创 Ubuntu下网络设定
工作中经常用到Ubuntu网络设定,以eth0为例,记录网络配置:首先 ifconfig -a 列出所有网口:然后进行网络配置,输入内容如下:auto eth0iface eth0 inet staticaddress 172.16.21.123netmask 255.255.255.0gateway 172.16.21.254broadcast 172.16.
2016-12-07 11:35:50 318
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人