- 博客(13)
- 收藏
- 关注
原创 python--PIL初探
from PIL import * image=Image.open('10.jpg') #box = (20, 0,70,55) #region = image.crop(box) #region = region.rotate(180) #image.paste(region,box) #width,height = image.size #image2=image.resize((width
2015-12-22 23:12:18
835
转载 python--requests下载图片
转载自http://stackoverflow.com/questions/13137817/how-to-download-image-using-requests You can either use the response.raw file object, or iterate over the response. To use the response.raw file-
2015-12-22 10:48:04
6051
原创 python--python3爬虫之模拟登录知乎
代码在python3环境下测试通过: from bs4 import BeautifulSoup import requests url = 'http://www.zhihu.com' login_url = url+'/login/email' captcha_url = 'http://www.zhihu.com/captcha.gif' headers={ 'Accep
2015-12-21 20:30:53
5702
原创 python--格式化打印
1.字符串方法(ljust,rjust,center,format) >>> s='格式化打印' >>> print(s.ljust(40,'-')) '格式化打印-----------------------------------' >>> print(s.rjust(40,'-')) -----------------------------------格式化打印 >>> print(s.
2015-12-14 08:54:36
1185
原创 python--回调函数
学习时遇到这样段代码: import re text = 'UPPER PYTHON, lower python, Mixed Python' def replace(m,word): text = m.group() if text.isupper(): return word.upper() elif text.islower():
2015-12-13 19:49:20
1616
转载 python-变量命名规范
块名、包名: 小写字母,单词之间用_分割 ad_stats.py 类名: (每个)单词首字母都要大写 AdStats ConfigUtil 全局变量名: 大写字母,单词之间用_分割 NUMBER COLOR_WRITE 普通变量: 小写字母,单词之间用_分割 this_is_a_var 常量 常量名所有字母大写,由下划线连
2015-12-09 20:12:02
1040
原创 python--格式化打印杨辉三角(format)
打印目标: >>> runfile('E:/桌面/代码池/untitled0.py', wdir='E:/桌面/代码池') num:11 1 1 1
2015-12-06 17:08:15
16227
原创 python--更干净的词频统计
上篇文章我们介绍了利用Counter模块轻松搞定词频统计的方法,因为重点是介绍模块的使用,代码显得比较粗糙。 import re,collections def get_words(file): with open (file) as f: words_box=[] for line in f:
2015-12-05 17:07:00
15493
原创 python--10行代码搞定词频统计
问题描述:现在有两篇英文电子书(含中文行),统计他们各自的单词出现次数并进行加和,结果以字典形式呈现: {'the': 2154, 'and': 1394, 'to': 1080, 'of': 871, 'a': 861, 'his': 639, 'The': 637, 'in': 515, 'he': 461, 'with': 310, 'that': 308, 'you': 295, 'fo
2015-12-05 15:44:36
54494
原创 python--删除队列重复元素
如何删除队列重复元素呢?简单地说,我们有两种实现的方法: 1.借助set函数先将列表转化为集合: a=[1,3,1,2,4,2,5,6] print(list(set(a))) 这种方法有两个局限:第一,转化后的list不再保持原有的顺序(因为set和dict一样是无序的);第二,如果列表中存在可变元素(list,dict,etc),那么也不能借助set来实现: a=[1,3,1,2,[4
2015-12-05 14:49:36
6164
原创 python--字典排序
prices = { 'ACME': 45.23, 'AAPL': 612.78, 'IBM': 205.55, 'HPQ': 37.20, 'FB': 10.75 }对于这样一个字典,如何根据价格来对字典进行排序呢? 首先你就会问,python中的字典明明是无序的,何谈排序之说?别急,办法总是有的。 对于这样一个字典的排序,直接使用sorted函数肯定
2015-12-05 11:27:55
801
原创 python--字典初始化
如果说deque是加强版的list的话,那加强版的字典又是什么的呢?没错,就是今天学习的defaultdict,它与deque一样,都是在collections库中的模块。 先来看这样一个问题:s = [('Tom', 5), ('Jone', 2), ('Susan', 4), ('Tom', 4), ('Tom', 1)] 对于这样一个元组列表,如果我们想要将它转化为字典,该如何操作呢?我们
2015-12-04 16:29:45
39001
原创 Python--加强版列表(deque)
python中的collections模块提供了很多有用的模块,其中的deque可以称得上是加强版的列表。 deque基本具备所有的列表方法: from collections import deque q=deque([1,2,3]) q.append(1) print(q) q.extend([4,5]) print(q) q.pop() print(q)运行结果是显而易见的: dequ
2015-12-04 15:13:52
2650
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人