自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(93)
  • 资源 (9)
  • 收藏
  • 关注

原创 一个数组分为N份

list_lenght = len(new_line_list) file_count = 3 partial_count = list_lenght/file_count for file_index in range(file_count): range_start = partial_count * file_index range_e

2015-03-01 21:28:55 1671

原创 cookie解析

__author__ = 'huafeng'#coding:utf-8import requestsurl = 'http://www.zhihu.com/topics#%E6%91%84%E5%BD%B1'# s = requests.session()r = requests.get(url)#如果不请求过程中不涉及session信息的修改,则无需使用request.session

2015-02-11 17:14:05 885

原创 python write, writelines性能分析

准备数据:1G文本数据(共:5193374行)1.write()with open() as wf:  wf.write(line)性能分析:写数据耗时:13.094s写入速度:6610.373708059671(行/秒)2.writelines()with open() as wf:  wf.writelines([line_list])性能分析:写数

2015-02-10 11:56:40 5342

原创 python数据结构内存占用分析

字典(dict):原始语料:546MCPU usage:36.7% ==> 76.9%占用内存3.2G     (占用空间为原始语料的6倍)查找时间复杂度:O(1)集合(set):原始语料:546MCPU usage:34.6%==>70.6%占用内存:2.88G     (占用空间为原始语料的5.4倍)查找时间复杂度:O(1)数组(List

2015-02-10 11:54:50 3121 1

原创 字典for in 性能测试

d = {}for i in range(100000000): d['%s'%i] = Noneprint len(d)#100000000start_time = time.time()print 'a' in d#Falseprint "in time consume: ", time.time() - start_time#in time consume: 0.0s

2015-02-10 11:52:19 622

原创 readline,readlines,read占用内存分析

原始语料:546M1.readlines() with codecs.open(combine_bigram_remove_freq_1_filename, encoding='utf-8') as f: temp_list = [item for item in f.readlines()]CPU usage:34.6% ==> 61.7%占用内存:2.168G耗

2015-02-10 11:50:02 1389

原创 读取文件总行数方法及性能比较

测试数据,大小:1G  总行数:5193911行实现方式:codecs.open(); open(); enumerate()常识:codecs open()时默认mode为'rb'; 直接使用open()打开默认方式为'r'先给出结论:1、同一种打开方式下mode=‘rb'性能高于mode='r'2、不同打开方式(codecs.open(), open()) 相同的mode时,二

2015-02-09 10:03:54 1347

原创 笛卡尔积,python实现以及改装

__author__ = 'wanghuafeng'# -*- coding: utf-8 -*-import timeimport itertoolsfor i in itertools.product([1, 2, 3], [4, 5], [6, 7]): print idef product(*args, **kwds): # product('ABCD',

2015-02-08 17:46:32 2017

原创 fabric remote usage

__author__ = 'huafeng'#coding:utf-8import osimport subprocessimport codecsimport simplejsonremote_path = r'/home/mdev/tmp'def tar_(): tar_command = '''fab -H mdev -- "cd %s;

2015-02-08 17:44:46 620

原创 检查字符串中的结束标记

给定一个字符串s,检查s是否含有多个结束标记中的一个。import itertoolsdef anyTrue(predicate, sequence): return True in itertools.imap(predicate, sequence)def endsWith(s, *endings): return anyTrue(s.endswith, endings

2015-02-08 17:41:59 561

原创 不打乱顺序的情况下去除数组中的重复元素

def unique_list(xs): seen = set() # not seen.add(x) here acts to make the code shorter without using if statements, seen.add(x) always returns None. return [x for x in xs if x not in seen

2015-01-14 18:03:24 628

原创 python 批量文件名转换

#coding:utf-8import globimport osdef files_rename(file_path_pattern, d): '''批量文件名转换''' file_list= glob.glob(file_path_pattern) for filename in file_list: path, pure_filename = o

2015-01-13 18:10:12 748

原创 将文件切割行数相等n个子文件

__author__ = 'huafeng'#coding:utf-8import sysimport osdef cut_file(filename, partial_count=1): with open(filename) as f: line_list = f.readlines() lenght_of_lines = len(line_li

2015-01-09 16:40:50 503

原创 python单例模式Singleton

__author__ = 'sivil'#coding:utf-8class Singleton(object): def __new__(cls, *args, **kwargs): if not hasattr(cls, '_instance'): orig = super(Singleton, cls) cls._

2015-01-08 09:35:07 778

原创 python 获取前一天日期以及字符串的格式化

__author__ = 'wanghuafeng'from datetime import timedelta, datetimeyesterday = datetime.today() + timedelta(-1)yesterday_format = yesterday.strftime('%Y_%m_%d')print yesterday_format #2015_01_05

2015-01-06 14:20:40 29910 3

原创 python接收代码参数,并通过eval()在代码中执行

def check(script): filename = r'F:\klm\wordservice\data\Cizu_and_singleword_komoxo95K.txt' script_compile = compile(script, '', 'eval')#预编译,耗时操作,列表解析中直接执行eval(),每次都会编译 with codecs.open(fil

2014-12-09 10:18:01 2825

原创 glob获取相关路径

def get_all_checkout_file(): '''利用glob获取相关路径''' import glob glob_path = os.path.join(PATH, '0709modify', 'cuted_varify_sample_pinyin_role_checkout*') matched_path_list = glob.glob(glo

2014-11-05 18:53:16 698

原创 ctypes使用

有关定义:__declspec(dllexport)

2014-11-05 18:23:40 653

原创 python 切词算法(正向切割、反向切割)

__author__ = 'wanghuafeng'#coding:utf-8import osimport sysimport codecsfrom collections import dequetry: PATH = os.path.dirname(os.path.abspath(__file__))except: PATH = os.getcwd()cl

2014-11-05 15:22:47 3186

原创 语料中筛选出英文单词并统计词频,正则切割匹配

#coding:utf-8import reimport osimport timeimport codecsPATH = os.path.dirname(__file__)s = u'what a Beautiful woRld'.lower()pattern = re.compile(u'[^a-z]+', re.U)#在非英文出进行切割for con in pattern

2014-10-31 18:13:04 1751

原创 python 斐波那契数列,查找素数,水仙花数字

def fbi(n): '''斐波那契数列''' if n<=2: return 1 else: return fbi(n-1) + fbi(n-2)# print fbi(8)def find_prime(start_num, end_num): '''找出start_num,与end_num之间的素数''' def

2014-10-31 14:33:00 1755

原创 python实现对数组去重排序操作

l = [1,3,3,4,2,1,3,4,5,6,7,8,6,5,4,2]def sort_(l): if len(l) <= 1: return l mid = l[0] low = [item for item in l if item < mid] high = [item for item in l if item > mid] r

2014-10-31 09:13:00 4224

原创 python实现线性表顺序存储的插入操作

def insert_list(L, i, element): L_lenght = len(L) if i L_lenght: return False if i <= L_lenght: for k in range(i-1, L_lenght)[::-1]: L[k+1:k+2] = [L[k]]

2014-10-30 08:51:33 2720

原创 文本第二列的长度进行排序,按奇偶行分离文本

import codecsimport ospath = os.path.dirname(__file__)odd_line_list = []even_line_list = []filename = os.path.join(path, 'forum_high_freq_sentence_sougou_checkout.txt')with codecs.open(filename

2014-09-24 15:27:36 588

原创 python exec, eval 方法整理

#coding:utf-8import osimport timeimport codecsdef get_lenght_single_word(): '''筛选出文件中不同长度的汉字''' filename = r'E:\SVN\linguistic_model\9_keys\0709modify\wordlist_61633_weight.txt' with

2014-09-18 15:05:32 696

原创 python 求前一天的时间

import datetimenow_time = datetime.datetime.now()print now_timeyesterday = now_time + datetime.timedelta(days=-1)print yesterday.strftime("%Y-%m-%d")

2014-07-01 14:28:01 975

原创 爬虫关于非规则html处理

html = r'''1/25 <a href=\"?cat=670%2C671%2C672& page=1\" class=\"prev\">上一页<a href=\"? cat=670%2C671%2C672&page=2\" class=\"next\">下一页'''html为网页中解析出的一个

2014-05-20 08:25:52 1838

原创 解析京东页面,生成以该页面为根的所有page_url

def parse_root_page_url(): # page_size_pattern = re.compile(r".*?(\d+)") url = 'http://list.jd.com/737-794-798.html' html = urllib2.urlopen(url).read() page_size_div_pattern = re.compi

2014-05-19 14:42:26 1638

原创 单线程代理无间隔抓取

目标网站:jd目标代理

2014-05-18 15:10:03 620

原创 Python豆瓣爬虫,指定文件行数写入到文件中

__author__ = 'huafeng'import osimport reimport timeimport codecsimport loggingimport urllib2import randomfrom math import ceilfrom bs4 import BeautifulSoupPATH = os.path.dirname(os.path.ab

2014-05-13 15:12:26 859

原创 取出list中时间轴时间的数据

def operate_file_list(): repeat_time_param_check_list = [] file_list = [";2014-05-01:7", 'a', 'b', 'c', ';2014-05-08:5', 'd', 'e', 'f', ';2014-06-01:4', 'g',

2014-05-12 11:55:55 1405

翻译 urllib2源码记录

"""An extensible library for opening URLs using a variety of protocolsThe simplest way to use this module is to call the urlopen function,which accepts a string containing a URL or a Request object

2014-04-25 08:38:30 708

原创 python logging 模块,logger.debug(),logger.info()等写入文件时的核心源码

def emit(self, record): """ Emit a record. If a formatter is specified, it is used to format the record. The record is then written to the stream with a trailing newli

2014-04-15 16:00:35 2347

原创 Python正则小实例

def re_test(): import re s = "gsmice@sina.cn : 测试账号 : 7568 : 06286ec389c5536914d63d094f93da7a" pattern = re.compile(r"^\s*(?P[^\s:]+)\s*:\s*(?P[^\s:]+)\s*:\s*(?P[^\s:]+)\s*:\s*(?P[^\s:]+)"

2014-03-31 20:16:00 529

原创 关于readlines与read效率的比较

因为多是以来一直使用f.readlines()来处理文件,今天看了一篇帖子说,f.read()的效率要高于f.readlines()而且f.read()还更智能。当然,“智能”这个词到底体现在哪我还不知道,但是效率觉得值得商榷,然后自己写个小程序测试下。有点坑了,所以嘛,有歧义的话,还是自己动手去验证吧。。。。测试文件大小为5M,近19万行。import timeimport codec

2014-03-14 09:42:58 3056 2

原创 Python .format(),%格式化时,对字符串编码方式的影响

1、当标准字符串和Unicode字符串在表达式中混合用时,标准字符串将被自动转换为Unicode字符串。例如:s = "hello"t = u"world"w = s + t #w = unicode(s) + t2、当一个字符串方法中使用到Unicode字符串时,结果也总将是Unicode字符串,例如:a = "Hello World"b = a.replace("Worl

2014-03-13 09:24:33 5962

原创 Python从同一文件进行数据不落地的取高频处理

数据格式:(词,拼音,词频)的 de 148709248的 di 1193135了 le 62873377了 liao 3199200是 shi 62432861一 yi 58994539不 bu 57479625不 fou 1136895将文件中多音字的高频词汇提取并返回def chose_high_freq_word(): '''ke

2014-03-12 14:35:47 972

原创 迭代器product

from itertools import productpinyin_list = [[u'shei shi', u'shui shi'], [u'kai fa'], [u'jiao cheng']]keys = []for i in range(len(pinyin_list)): tmp_keys = [item for item in pinyin_list[i]]

2014-03-11 20:26:05 593

原创 生成器表达式

arr = ['11', '4', '3', '2', '1']arr = [int(val_int) for val_int in arr]print arrprint [float(item)/sum(arr) for item in arr]

2014-03-07 14:45:29 513

原创 python爬虫模拟人人网登陆并发表更新状态

网上找了一些资源,python爬虫模拟登陆人人网的例子,但是应该是比较早期的版本,大多已经无法登陆。而且人人网也在做一些信息验证机制也在变化,自己做了一个小爬虫,模拟登陆后在人人网发表自己的状态。登陆是需要的信息:    postData = {'email':username,'password':password}发表心情是所需的信息:            statusD

2014-03-03 08:31:35 1260

php cookbook

php 进阶, cookbook经典系列

2015-11-03

python twisted系列

python twistd异步相应框架,相关书籍,文档

2014-11-20

C程序设计语言

c语言圣经,主要是,CSDN上这本书下载资源都是要积分的(反人类),还是上传一份免分的吧。

2014-11-10

prn格式详解

prn格式详细说明,条形码与prn文件,打印机读取文件格式

2013-05-09

python 64位常用module

比较常用的python模块,数据库交互,定时,redis,lxml, flask等等

2013-05-08

oracle导入导出操作

oracle表空间建立,impdp/expdp的操作

2013-04-28

python知识点

python http一些操作 连接url抓取网页数据

2013-04-28

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除