学以致用

focus on Python , C++, and some interest in Go and R

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

随笔分类 -  python相关

1 2 3 4 下一页

主要包括python各种库的使用
摘要:# install python3sudo yum -y updatesudo yum -y install yum-utilsyum install -y zlib-devel bzip2-devel ncurses-develyum install libffi-develsqlite-deve 阅读全文
posted @ 2019-04-08 16:45 Jerry.Kwan 阅读(214) 评论(0) 推荐(0)

摘要:# install TensorFlow GPU on CentOS 7.0# https://www.server-world.info/en/note?os=CentOS_7&p=tensorflow&f=2# https://docs.nvidia.com/cuda/cuda-installa 阅读全文
posted @ 2018-06-07 11:24 Jerry.Kwan 阅读(270) 评论(0) 推荐(0)

摘要:sudo apt install python-minimal # python 2.7.xsudo apt install python-pip# https://www.ubuntuupdates.org/ppa/google_chromewget -q -O - https://dl-ssl. 阅读全文
posted @ 2017-08-21 22:34 Jerry.Kwan 阅读(314) 评论(0) 推荐(0)

摘要:http://p-nand-q.com/python/building-python-27-with-vs2010.html 阅读全文
posted @ 2015-12-30 14:05 Jerry.Kwan 阅读(325) 评论(0) 推荐(0)

摘要:对于Python2.7来说,内置的FTP_TLS类并不支持Implicit FTP Over TLS加密方式的FTP Server操作,为支持Implicit FTP Over TLS加密方式,必须重载内置的FTP_TLS类,具体代码如下:import ftplibclass FTP_TLS(ftp... 阅读全文
posted @ 2015-09-11 15:29 Jerry.Kwan 阅读(2735) 评论(0) 推荐(0)

摘要:使用python实现的树遍历,包括宽度优先和深度优先ef dfs(): tree = { 'A': ['B', 'C'], 'B': ['D', 'E'], 'C': ['F', 'G'], 'D': ['H', 'I'], ... 阅读全文
posted @ 2015-04-04 09:29 Jerry.Kwan 阅读(1030) 评论(0) 推荐(0)

摘要:在安装lxml时出现如下错误gcc: internal compiler error: Killed (program cc1)通过查看dmesg发现下述错误信息[2517343.500178] Out of memory: Kill process 5051 (cc1) score 632 or ... 阅读全文
posted @ 2015-01-12 10:41 Jerry.Kwan 阅读(3788) 评论(0) 推荐(0)

摘要:scapy在linux环境中对pcap文件进行操作非常方便,但在windows下,特别是在python2.7环境下却会碰到各种各样的依赖包无法使用的问题,最明显的可能就属dnet和pcap的python依赖包了,因为scapy的conf.use_pcap和conf.use_dnet在windows环... 阅读全文
posted @ 2014-11-05 17:00 Jerry.Kwan 阅读(11757) 评论(2) 推荐(1)

摘要:import sysimport osimport reimport datetimeimport csvdef get_datetime(record): request_time = "" p = re.compile(r"(?P\d{4}-\d{2}-\d{2} \d{2}:\d{... 阅读全文
posted @ 2014-10-31 11:26 Jerry.Kwan 阅读(3760) 评论(0) 推荐(0)

摘要:相信很多使用python者都对reload方法比较熟悉了,通过不间断地reload可以实现某一module的热更新,主要就能在不重启应用的情况下实现部分模块的更新。但这种方法仅限于reload当前工作目录下的module,对于通过setuptools安装的egg包就不灵了,具体分析如下:(1)python 的import或者reload都是根据sys.path来进行查找相关module的,找到第一个匹配的module之后就进行加载然后退出此操作(2)sys.path是有一定的顺序的(3)通过setuptools 的easy_install进行安装的package,每个版本都保留在site-pa 阅读全文
posted @ 2014-01-06 14:39 Jerry.Kwan 阅读(631) 评论(0) 推荐(0)

摘要:在使用Request上传文件的时候碰到如下错误提示:2013-12-20 20:51:09,235 __main__ ERROR 'ascii' codec can't decode byte 0xe7 in position 27379: ordinal not in range(128)Traceback (most recent call last): File "server_merge.py", line 251, in avml_storage result_f , result_m = avml_storage.uploadData( 阅读全文
posted @ 2013-12-22 12:14 Jerry.Kwan 阅读(1474) 评论(0) 推荐(0)

摘要:访问远程libvirtd服务因为是在一个可信环境中运行,所以可以忽略安全方面的操作,步骤如下:(1)更改libvirtd配置 1.1 更改/ect/sysconfig/libvirtd文件,打开LIBVIRTD_ARGS="--listen"设置 1.2 更改/etc/libvirt/libvirtd.conf listen_tls = 0 #关闭tls listen_tcp = 1 # 打开tcp tcp_port = "16509" # 侦听关口 listen_addr="0.0.0.0" # 侦听地址 auth_tcp = &q 阅读全文
posted @ 2013-12-20 16:53 Jerry.Kwan 阅读(670) 评论(0) 推荐(0)

摘要:获得当前所有logger的列表的程序如下:import loggingfor name in logging.Logger.manager.loggerDict.keys(): logger = logging.getLogger(name) print 'name = %s, logg... 阅读全文
posted @ 2013-09-04 15:02 Jerry.Kwan 阅读(1592) 评论(0) 推荐(0)

摘要:使用python生成或者解析xml的方法用的最多的可能就数python标准库xml.etree.ElementTree和lxml了,在某些环境下使用xml.etree.ElementTree更方便一些,毕竟是python2.5以后的标准库。没想到的是python标准库中竟然存在这么一个低级的bug,简单来说就是某种情况下使用ElementTree序列化的xml数据竟然无法正常解析。仔细分析之后发现是因为charset的原因,但为何不在序列化的时候就做一些检测,进行相应提醒呢?也不至于出现自己序列化自己却不能正常解析的尴尬局面了吧?这点和lxml相比就差远了。具体示例如下:def test_lx 阅读全文
posted @ 2013-08-27 16:08 Jerry.Kwan 阅读(1004) 评论(0) 推荐(0)

摘要:python的Requests(http://docs.python-requests.org/en/latest/)库在处理http/https请求时还是比较方便的,应用也比较广泛。但其在处理response时有一些地方需要特别注意,简单来说就是Response对象的content方法和text方法的区别,具体代码如下:@property def content(self): """Content of the response, in bytes.""" if self._content is False: # Read the 阅读全文
posted @ 2013-08-21 15:21 Jerry.Kwan 阅读(5484) 评论(0) 推荐(0)

摘要:在使用python的json模块对json字串反序列化成python对象的时候出现的字符串都是unicode类型,而不是python内置的str类型。在某种使用场景下用户必须做显式的转换才能正常使用,徒增一些麻烦,为解决这一问题封装下述函数。def convert(input): if isinstance(input, dict): return {convert(key): convert(value) for key, value in input.iteritems()} elif isinstance(input, list): return ... 阅读全文
posted @ 2013-07-24 10:03 Jerry.Kwan 阅读(4552) 评论(0) 推荐(0)

摘要:以下代码仅作为参考之用select md5, crc32, record->'UserModerAnalysis'->'base_info'->'file_malware' as file_malwarefrom reportsCREATE OR REPLACE FUNCTION py_get_file_malware(record TEXT) RETURNS TEXTAS $$ # pl/python functioin body import json plpy.notice('type of record is&# 阅读全文
posted @ 2013-06-20 10:37 Jerry.Kwan 阅读(4132) 评论(0) 推荐(0)

摘要:在使用createlang 安装plpythonu的时候出现如下错误:could not open extension control file "/usr/share/postgresql/9.1/extension/plpythonu.control": No such file or directory主要原因是安装postgresql的时候没有使用--with-python选项编译好PL/Python对于已经安装好的postgresql可以通过以下方式解决缺少依赖包的问题:sudo apt-get install postgresql-plpython安装好post 阅读全文
posted @ 2013-06-18 10:43 Jerry.Kwan 阅读(4703) 评论(0) 推荐(0)

摘要:在做搜索服务的时候,拼写检查应该算是一个锦上添花的功能点,相信大家都还对google的Did you mean:XXX印象深刻,这个是怎么实现的呢?在使用sphinx搜索引擎的时候又能怎么做呢?转载网上的两篇文章:http://norvig.com/spell-correct.htmlhttp://sphinxsearch.com/forum/view.html?id=3709 阅读全文
posted @ 2013-05-27 15:04 Jerry.Kwan 阅读(239) 评论(0) 推荐(0)

摘要:将使用cx_freeze打包的python程序copy到别的机器上运行时碰到这样的错误:jerrykwan@jerrykwan:~/Downloads/exe.linux-x86_64-2.7$ ./server_family_info Traceback (most recent call last): File "/usr/local/lib/python2.7/site-packages/cx_Freeze/initscripts/Console.py", line 27, in <module> File "server_family_info 阅读全文
posted @ 2013-04-03 16:42 Jerry.Kwan 阅读(17060) 评论(0) 推荐(1)

1 2 3 4 下一页