
python
xyqzki
wahahahaahahahahah
展开
-
CENTOS7安装VIM插件YOUCOMPLETEME
来自: Dreamlike博客,本文链接: CentOS7安装Vim插件YouCompleteMeYouCompleteMe这个Vim插件还真不好安装,挺多坑的,折腾了挺久终于最后用上了。测试环境:[broly@localhost ~]$ cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core)一、更新Vim我安装这个插件的时候,提示转载 2018-01-22 16:34:48 · 8193 阅读 · 1 评论 -
python 比较两个序列的相似度,不需要分词
code通过Python来判断2个文字列的相似度的多少,合理使用的话就可以实现Google等搜索引擎中的 你是不是要找 的功能了。import diffliba=u'阿里巴巴'b=u'阿里爸爸'print difflib.SequenceMatcher(None,a,b).ratio()0.75返回的结果超过0.6就算很相似。看来目前完全人肉做近义词词典的工作有一部分可以自动化来实现了。ref转载 2015-07-09 11:03:42 · 14482 阅读 · 2 评论 -
python 合并列表的列表
list=[['aa', 'bb'], ['cc', 'dd']] >> print [j for i in list for j in i]['aa', 'bb', 'cc', 'dd'] >> print sum(list,[]) ['aa', 'bb', 'cc', 'dd'] >> t=[] >> [t.extend(i) for i in list转载 2015-07-09 11:00:20 · 3111 阅读 · 0 评论 -
python 处理中文需要注意的编码问题
ref: http://wklken.me/posts/2013/08/31/python-extra-coding-intro.htmlnote:主要分str 和 unicode两种类型。用type来查看str是又unicode encode之后得到的。所以str不能encode,而unicode不能decode进来的string,全部用decode(“utf-8”)转换成unicode原创 2015-06-05 17:18:36 · 541 阅读 · 0 评论 -
python 工具包总结
Python Basic Modulesref: http://kenanbek.me/post/guide-to-python-data-mining-data-analysis-and-data-visualisation-with-tutorials-and-samples/ - numpy – Numerical library - scipy – Advanced math, sign原创 2015-05-19 10:17:49 · 1101 阅读 · 0 评论 -
如何在没有root权限的情况下安装numpy 和scipy python module
参考: http://www.hongliangjie.com/2012/04/01/install-numpy-and-scipy-on-centos-without-root-privilege/Sometimes you want to install Numpy and Scipy on a remote CentOS machine without root privilege, whi转载 2015-06-03 14:55:14 · 3150 阅读 · 0 评论 -
python 工具包总结
Python文本网络分析工具包textplothttps://github.com/davidmcclure/textplothttp://dclure.org/essays/mental-maps-of-texts/http://pan.baidu.com/s/1ntzdM57原创 2015-05-15 09:53:34 · 505 阅读 · 0 评论 -
用python爬网页数据
http://my.oschina.net/chenyublog/blog/142895Python 爬虫python版本2.7,操作系统ubuntu12.04,我是在eclipse实验的。下面是爬互联网网页数据的一些经验。爬取网页数据核心就是解析网页源文件,思路就是先把网页所有源代码缓存到本地,然后通过软件包或者自己使用正则表达式提取想要找的东西。核心包就是u转载 2015-04-12 22:42:48 · 3721 阅读 · 0 评论 -
Python的函数参数传递:传值?引用?
作者:winterTTr (转载请注明)我想,这个标题或许是很多初学者的问题。尤其是像我这样的对C/C++比较熟悉,刚刚进入python殿堂的朋友们。C/C++的函数参数的传递方式根深蒂固的影响这我们的思维--引用?传值?究竟是那种呢。呵呵,语言的特性决定了是使用的方法,那么,现在我们来探究一下python的函数参数传递方式。在开始之前,我们有必要分清一下pytho转载 2015-03-31 22:13:10 · 450 阅读 · 0 评论 -
python 字符编码
1. 字符编码简介1.1. ASCIIASCII(American Standard Code for Information Interchange),是一种单字节的编码。计算机世界里一开始只有英文,而单字节可以表示256个不同的字符,可以表示所有的英文字符和许多的控制符号。不过ASCII只用到了其中的一半(\x80以下),这也是MBCS得以实现的基础。1.2. MBCS转载 2014-12-27 11:21:20 · 524 阅读 · 0 评论 -
python 处理中文 读取数据库输出全是问号
ref:http://www.cnblogs.com/zhoujie/archive/2013/06/07/problem1.html1、python连接mssql数据库编码问题 python一直对中文支持的不好,最近老遇到编码问题,而且几乎没有通用的方案来解决这个问题,但是对常见的方法都试过之后,发现还是可以解决的,下面总结了常用的支持中文的编码问题(这些方法中可能其中一个就能转载 2015-07-15 13:01:36 · 16449 阅读 · 0 评论 -
jieba分词,导入新词库出现的global name f_name is not defined
https://github.com/fxsjy/jieba/pull/257/filespath : /home/yqxu/install/lib/python2.7/site-packages/jieba/__init__.py在__init__.py中改掉这一行就可以了。tup= line.split("") add_原创 2015-07-15 14:39:00 · 3043 阅读 · 0 评论 -
python 关于yield, generator, iterable
遍历一个list,寻找满足条件的元素。如果这个list很长,则不要直接iterable 这个list,即使用for 遍历,将整个list全部放到memory中。最好的办法是用yield create一个generator。这样就是每scan一个元素就放入内存。see http://pythontips.com/2013/09/29/the-python-yield-keyword原创 2015-12-07 11:39:53 · 491 阅读 · 0 评论 -
关于python刷题的语法要点
list a, bb = a, it is just a reference assignment. a改变,b也改变b = a[:], it is copy. a 改变,b不变原创 2015-12-13 22:23:14 · 858 阅读 · 0 评论 -
python 中的counter类用法。重要
是dict的子类,2.7的时候引入http://www.pythoner.com/205.html原创 2015-12-10 20:38:27 · 8339 阅读 · 0 评论 -
python 中的counter类用法。重要
是dict的子类,2.7的时候引入http://www.pythoner.com/205.html原创 2015-12-10 20:38:30 · 2041 阅读 · 0 评论 -
python 函数中或者new一个对象的时候 默认值如果设为list, dict, or sets要注意
ref:http://docs.python-guide.org/en/latest/writing/gotchas/函数的默认值要注意!!!如果是list, dict ,sets 给默认值得时候 不要在arguments 里面给,要在函数内部给exampleclass T:def __init__(self, a1 = []):self.a1 =转载 2015-10-14 17:11:24 · 1639 阅读 · 0 评论 -
用MD5生成唯一性的id
http://pythoncentral.io/hashing-strings-with-python/转载 2015-08-19 16:35:07 · 7745 阅读 · 0 评论 -
python 转化object 到json 然后存入redis以及从redis读取
object - > jsonr = redisconnect(0)prev_topicList_redis = r.get("BIGDATA.NEWS_CLUSTER:cn.dup_by_generator.3")#read from redis, but the prev_topicList is a dict rather than a object prev_topicList = j原创 2015-08-19 16:28:38 · 7840 阅读 · 0 评论 -
python 面向对象 继承
http://www.cnblogs.com/Joans/archive/2012/11/09/2757368.html转载 2015-07-17 14:32:39 · 570 阅读 · 0 评论 -
【整理】关于Python脚本开头两行的:#!/usr/bin/python和# -*- coding: utf-8 -*-的作用 – 指定文件编码类型
http://www.crifan.com/python_head_meaning_for_usr_bin_python_coding_utf-8/转载 2014-12-27 10:44:54 · 1004 阅读 · 0 评论 -
win7安装ubuntu 14以及python环境,不同版本python之间切换(virturalenv)
win7安装ubuntu14参考:win7安装ubuntu14 更新语言支持: system setting->language support 安装搜狗拼音+ sublime : 装好之后,还要添加sougou pinyin. 点击“配置输入法”对话框左下角的加 号“+”,选上“only for cur原创 2014-12-09 23:01:19 · 1344 阅读 · 0 评论 -
python 面向对象编程
1. 每个类方法都要有self作为参数,但可以不传递这个参数2. 创建一个instance,用 A = CLASSNAME (); 可以有参数3. 主程序用 if __name__ == "__main__":4. 如果名称前加油两个下划线,表示是private的属性5. OOP: 域 field or attribute方法 method原创 2014-12-24 16:06:46 · 554 阅读 · 0 评论 -
python 如何安装第三方模块module
for example1、下载:chardet-1.0.1.tar.gz #md5=7c28b02bca7847c13bebedaf4df6c5a3" target="_blank" rel="nofollow">http://pypi.python.org/packages/source/c/chardet/chardet-1.0.1.tar.gz#md5=7c28b02b转载 2013-10-31 22:10:34 · 5158 阅读 · 0 评论 -
如果python程序写硬盘太慢,可以考虑输出为二进制。且save 和load 都用pickle比较方便
import pickle用字典做了文本数据的统计,但是还没有统计完,需要第二天继续,所以用到了数据持久化部分。简单记录字典的保存和导出。import pickle# create dictlist = {"01":02,"02":03,"03":04}# save dictf1 = open("E:\\test.txt","wb")pickle.dump(li转载 2013-10-31 10:52:13 · 3300 阅读 · 0 评论 -
python error: IndentationError: unindent does not match any outer indentation level
occur at the position where you mix tabs and spaces. you just need to del all of them and press tab button sucessivelyref: http://stackoverflow.com/questions/492387/indentationerror-unindent-does-no转载 2013-10-30 16:36:48 · 1229 阅读 · 0 评论 -
给定element,求此element在list中的 index or position
ref http://www.cnblogs.com/Kaysin/archive/2013/02/08/2909402.html我们没有测试index,因为index 有个比较有趣的现象,让我们来试一下。# 位置 1 2 3 4 5 6 7# 序号 0 1 2 3 4 5 6a_list =['a','b',转载 2013-10-30 16:22:21 · 874 阅读 · 0 评论 -
批量replace method python
ref: http://stackoverflow.com/questions/10017147/python-replace-characters-in-stringTry regular expressions: a = re.sub('[.!,;]', '', a)You can also built an expression dynamically转载 2013-10-29 23:32:24 · 1495 阅读 · 0 评论 -
python 建立vocabulary,包括去标点,split
http://www.cnblogs.com/sunada2005/archive/2013/05/01/3053377.html一、统计txt中英文单词出现的次数 1 import string #处理文本时,需要去除跟在单词后的标点。所以用到string模块 2 3 filename=open('sampleFile.txt')转载 2013-10-29 22:56:41 · 6804 阅读 · 0 评论 -
python 对string去掉标点符号
delset = string.punctuationl = line.translate(None,delset)print l 即为去掉标点符号的 string,而line本身没有变化原创 2013-10-29 22:48:11 · 39800 阅读 · 2 评论 -
在linux服务器某文件夹下,使用鼠标进行copy,move,其实还是会在目录下留有name.txt~的临时文件
程序如果以这个目录为dataset 运行的话 结果会有错误。。解决方法就是 用shell命令对这些txt~文件进行删除 rm原创 2013-10-28 17:34:12 · 924 阅读 · 0 评论 -
python中startswith与endswith方法
注意:是startswith 而不是 startwith,有个serror如果是 str has no startwith attribute。。。可能是方法名写错了或者类型不对原创 2013-10-28 17:09:39 · 4907 阅读 · 2 评论 -
python的输出 print print, write
1. 一般格式化输出记得加括号, 且无逗号 print "%d" % (variable)2. print "hello" 自带\n3. print "hello", 加上逗号之后,不会换行,但会加一个空格4. 如果print加逗号不换行的话会有一个空格 而sys.stdout.write()就没有;5. %r是一个万能的格式付,它会将后面给的参数原样打印出来,带有原创 2013-11-01 10:02:05 · 3290 阅读 · 0 评论 -
topic model 预处理步骤
1. del punctuation2. lower case3. del stopword4. len(s)>15. del infrequent word原创 2013-10-30 10:56:44 · 807 阅读 · 0 评论 -
python #!/usr/bin/python作用
#!/usr/bin/python指定用什么解释器运行脚本以及解释器所在的位置# -*- coding: utf-8 -*-用来指定文件编码为utf-8的PEP 0263 -- Defining Python Source Code Encodingshttp://www.python.org/dev/peps/pep-0263/估计有不少人注意过一些python脚转载 2014-12-23 21:55:18 · 5241 阅读 · 0 评论 -
python 处理中文遇到的编码问题总结 以及 字符str的编码如何判断
general :尽量把所有的input 都decode成unicode。即 str.decode('')转载 2014-07-25 11:42:47 · 24734 阅读 · 2 评论 -
理解Python的With语句
http://python.42qu.com/11155501转载 2014-09-28 17:08:59 · 449 阅读 · 0 评论 -
python写递归出现的错误
23 def Backtrace_catID(mycur,catID): 24 mycur.execute('SELECT * FROM category where categoryid = %s', catID) 25 catid_info = mycur.fetchall() 26 # print 'len(catid_info) =原创 2014-08-11 22:09:02 · 1915 阅读 · 0 评论 -
关于python自增运算
刚开始学 python,当想要自增运算的时候很自然的 a++,结果发现编译器是不认识 ++ 的,于是去网上搜了一下,结果发现一篇老外的问答很精彩,涉及到了 python 这个语言的设计原理问题无外乎就是 python 没有自增运算符,自增操作是如何实现的回答中有人介绍了关于自增操作,python 不使用 ++ 的哲学逻辑:编译解析上的简洁与语言本身的简洁,就转载 2014-08-07 10:46:59 · 93204 阅读 · 8 评论 -
python安装第三方的包
第一种基本安装方法1 下载第三方包,解压2 在命令提示符里输入cmd,然后用cd进入到第三方包的路径下3 输入python setup.py build4 输入python setup.py install看到包内的文件在安装即可……第二种 用pip和virtualenv安装p可以很方便的安装、卸载和管理Python的转载 2014-08-07 10:35:44 · 109257 阅读 · 1 评论