
python
iteye_20817
这个作者很懒,什么都没留下…
展开
-
swig官方学习笔记(c++ and python)
test.cpp #include <iostream>int go() { std::cout << "GOGOGOG" << std::endl; return 0;}int main(int argc, char **argv) { go();} test....原创 2015-04-09 17:52:12 · 236 阅读 · 0 评论 -
使用python class变量的风险
class Parent(object): x = 1class Child1(Parent): passclass Child2(Parent): passprint Parent.x, Child1.x, Child2.x# 1 1 1Child1.x = 2print Parent.x, Child1.x, Child2.x...原创 2016-12-14 12:50:36 · 455 阅读 · 0 评论 -
python itertools_groupby使用示例(转)
转自: http://freshfoo.com/blog/itertools_groupby A relatively unknown part of the Python standard library that I find myself using fairly regularly at work these days is the groupby function in th...原创 2013-04-29 22:31:36 · 781 阅读 · 0 评论 -
pip常用命令
下面以操纵uWSGI举例: #安装软件sudo pip install uWSGIsudo pip install uWSGI==1.9.4 #升级软件sudo pip install -U uWSGI==1.9.5 #卸载软件sudo pip uninstall uWSGI #查看安装软件pip freeze --end ...原创 2013-04-18 08:06:05 · 92 阅读 · 0 评论 -
uWSGI的harakiri参数不生效问题解决(harakiri not work)
当客户端请求uWSGI接口超过30s时,uWSGI会强制关闭客户端连接,然后重启响应客户端的worker。可以通过超时参数"-t | --harakiri"进行配置,我在uWSGI1.4.3版本设置该参数,但是配置在30s以内是有效的,超过30秒,则会和设置30s是一样结果,无奈之下升级至1.9.6版本,问题迎刃而解,这是uWSGI的bug。 P.S. 我的项目时flask项目...原创 2013-04-17 14:29:59 · 3004 阅读 · 1 评论 -
SQLAlchemy打印SQL语句
SQLAlchemy打开SQL语句方法如下,echo=true将开启该功能: engine = create_engine("<db_rul>", echo=True) Flask-SQLAlchemy打开SQL方法如下: app.config["SQLALCHEMY_ECHO"] = True --end ...原创 2013-04-15 15:12:07 · 2168 阅读 · 0 评论 -
uWSGI参数说明(转)
转自:http://www.cnblogs.com/zhouej/archive/2012/03/25/2379646.html原文地址:http://projects.unbit.it/uwsgi/wiki/DocuWSGI参考资料(1.0版本的配置选项列表)下面的内容包含了大部分uWSGI的配置选项,这些配置选项的列举没有特定的顺序。每一个选项都可以使用在任何一种支持的配置方...原创 2013-04-15 10:14:06 · 996 阅读 · 0 评论 -
python对XML的解析(转)
python有三种方法解析XML,SAX,DOM,以及ElementTree###1.SAX (simple API for XML ) pyhton 标准库包含SAX解析器,SAX是一种典型的极为快速的工具,在解析XML时,不会占用大量内存。但是这是基于回调机制的,因此在某些数据中,它会调用某些方法进行传递。这意味着必须为数据指定句柄,以维持自己的状态,这是非常困难的。###2....原创 2013-03-13 12:01:06 · 122 阅读 · 0 评论 -
python下“No module named sqlsoup”错误
今天部署新程序,报如下错误:写道No module named sqlsoup错误行:from sqlalchemy.ext.sqlsoup import SqlSoup 问题原因:sqlalchemy版本安装不对,0.8版本对api进行了调整,通过如下步骤消灭问题: pip uninstall sqlalchemy pip install http://pypi.pyt...原创 2013-03-09 16:55:29 · 165 阅读 · 0 评论 -
(转)python中cx_Oracle模块安装遇到的问题与解决方法
安装或使用cx_Oracle时,需要用到Oracel的链接库,如libclntsh.so.10.1,否则会有各种各样的错误信息。 安装Oracle Instant Client就可得到这个链接库,避免安装几百兆之巨的Oracle Client。 软件下载地址:cx_Oracle的主页:http://cx-oracle.sourceforge.net/必需的Oracl...原创 2013-02-24 10:23:57 · 201 阅读 · 0 评论 -
python高级编程——多进程包multiprocessing
1. 使用map方法 import multiprocessingimport timedef f(x): time.sleep(2) print xif __name__ == '__main__': pool = multiprocessing.Pool(processes=5) pool.map(f, xrange(10))...原创 2014-06-17 12:22:43 · 283 阅读 · 0 评论 -
python dict根据key和value排序
根据key排序a = {'a':1, 'c':2, 'b':3}[(k,a[k]) for k in sorted(a.keys())]#返回 [('a', 1), ('b', 3), ('c', 2)] 根据value排序a = {'a':1, 'c':2, 'b':3}sorted(a.items(), key=lambda d:d[1], reverse =...原创 2017-02-14 19:37:28 · 859 阅读 · 0 评论 -
python高级编程——方法参数*args与**kwargs
1. *args使用说明 def test(a,*args): print a print argstest(1,2,3,4)输出: 1(2, 3, 4) 2. **kwargs 使用方法 def test(a, **kwargs): print a print kwargstest(1, s1='CN', ...原创 2014-08-04 09:53:12 · 112 阅读 · 0 评论 -
swig官方学习笔记(c and python)
跟随官方教程 1. 编写C文件example.c #include <time.h> double My_variable = 3.0; int fact(int n) { if (n <= 1) return 1; else return n*fact(n-1); } int my_mod(int x, ...原创 2015-04-09 11:51:52 · 415 阅读 · 0 评论 -
python使用easy_install错误一例
$easy_install simplejsonSearching for simplejsonReading https://pypi.python.org/simple/simplejson/Download error on https://pypi.python.org/simple/simplejson/: [Errno 1] _ssl.c:510: error:14090...原创 2015-02-11 14:54:09 · 795 阅读 · 0 评论 -
python运行报错“UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position”
这里是运行安装包的时候报错,初步诊断下,感觉可能是对python系统文件添加了中文字符导致了,折腾下没有解决,后来果断重新安装,就OK了。原创 2014-12-13 11:42:41 · 519 阅读 · 0 评论 -
安装easy_install报错“urllib2.URLError: <urlopen error unknown url type: https>”
yum install openssl-devel重新编译、安装python --end原创 2014-11-10 15:34:59 · 395 阅读 · 0 评论 -
python高级编程——Decorator(修饰器)用法
一、基本应用: 在python里方法也是对象,它可以作为参数传递。现在有个方法foo,我希望在它运行前后做些事情,那就可以使用decorator了。 # coding=utf-8# 原方法def foo(): print 'running'# 修饰方法def outer(some_func): def inner(): ...原创 2014-11-06 09:09:49 · 289 阅读 · 0 评论 -
Sublime text 3 中文文件名显示方框怎么解决?(转)
这个是sublime text 3的bug,当Windows 个性化 显示 中的设置自定义文本大小(DPI),大于默认的100%的时候,就会出现这个bug。解决方法:在sublime text 3中,Preference, Settings-User,最后加上一行"dpi_scale": 1.0覆盖操作系统设置的DPI。这是我的Settings-User{"font_face": "Consol...原创 2014-11-05 17:50:03 · 516 阅读 · 1 评论 -
Shared counter with Python's multiprocessing(转)
One of the methods of exchanging data between processes with the multiprocessing module is directly shared memory via multiprocessing.Value. As any method that's very general, it can sometimes be tri...原创 2014-10-29 12:03:51 · 173 阅读 · 0 评论 -
python多进程全局共享counter(multiprocessing包实现)
# -*- coding: UTF-8 -*- from multiprocessing import Pool, Lock, Valueimport ostests_count = 80lock = Lock()counter = Value('i', 0) # int type,相当于java里面的原子变量def run(fn):...原创 2014-10-28 12:01:06 · 765 阅读 · 0 评论 -
netbeans下优秀sublinme主题
推荐站点:http://netbeansthemes.com/ 推荐主题:Monokai Sublime:rank排行最热门主题,但是它选择变量时,高亮和背景无法区分,个人受不了这个功能。Monokai Remix:它是第二名,主题也不错,但是使用后中文变乱码....Monokai :第三名,目前是我使用的主题--end ...原创 2014-09-29 10:13:43 · 417 阅读 · 0 评论 -
python中range()与xrange区别
1. range()返回一个list,xrange()返回一个迭代对象 print range(10)print xrange(10)print type(range(10))print type(xrange(10))输出:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]xrange(10)<type 'list'>&...原创 2014-09-11 16:39:51 · 214 阅读 · 0 评论 -
python oracle查询中文乱码(问号)问题
用的是sqlalchemy,在测试机器上部署查询中文为"?",简单设置如下: 设置一: import os os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8' 设置二: # -*- coding: utf-8 -*- --end ...原创 2013-01-08 08:57:10 · 1021 阅读 · 0 评论 -
sublime text3 设置空格可视化
Prefences -> 用户设置添加一行"draw_white_space": "all", --end原创 2014-05-27 16:22:53 · 1159 阅读 · 0 评论 -
sublime text2 配置tab为4个空格(转)
Preference-defalut:【将Tab键自动替换为4个空格】// The number of spaces a tab is considered equal to"tab_size": 4,// Set to true to insert spaces when tab is pressed"translate_tabs_to_spaces": true, 转自...原创 2014-05-27 16:21:32 · 163 阅读 · 0 评论 -
python nose学习笔记
安装:easy_install nose网络有问题就根据easy_install的nose下载url使用迅雷下下来,然后执行:python setup.py install 运行nose的命令: >nosetests /path/to/a_test.py:TestCaseCLassName.test_xxx_method --heipark ...原创 2012-11-14 21:23:48 · 208 阅读 · 0 评论 -
Sublime Text 快捷键学习笔记
快捷键: Ctrl + D:多选功能:相同单词选择,可以直接操作多个相同单词。适合如改名等动作。Alt + F3:选中所有相同的单词Ctrl+shift+K:删除光标所在行Ctrl + F3:快速查找选中文字NextCtrl + L: 选中当前行Shift + 鼠标右键(或者鼠标中键,快捷键Ctrl+shift +L):列选择Alt + Shift + 2|3|...原创 2012-11-13 22:40:46 · 115 阅读 · 0 评论 -
python类变量,类方法,静态方法
一、class object、class variable首先class在python里面是一个对象,它有独立区域存储属于自己的数据,而不需要实例化。 class Hehe(object): count = 0 # class variable def __init__(self, c): Hehe.count = ...原创 2015-08-05 11:52:03 · 207 阅读 · 0 评论 -
python2.7 print不换行的三种方法
方法一:import syssys.stdout.write("go ")sys.stdout.write("home")sys.stdout.flush() 方法二:函数方式调用print函数from __future__ import print_functionprint('go ', end='')print('home', en...原创 2015-07-30 10:54:12 · 3927 阅读 · 0 评论 -
使用python SimpleHTTPServer 快速搭建Web服务器
python -m SimpleHTTPServer 8080 #不指定端口默认为8000 执行上面的命令,就会启动web服务器了,可以下载用户启动路径的文件。一个网友根据SimpleHTTPServer源码写了一个支持上传功能的版本。我贴到附件。 参考:http://coolshell.cn/articles/1480....原创 2012-05-24 09:43:06 · 395 阅读 · 0 评论 -
记录一下python easy_install和pip安装地址和方法
安装easy_installwget http://peak.telecommunity.com/dist/ez_setup.py python ez_setup.py 安装pipwget https://pypi.python.org/packages/source/p/pip/pip-1.4.tar.gz#md5=ca790be30004937987767eac42cfa4...原创 2013-07-31 21:54:13 · 125 阅读 · 0 评论 -
python运行错误
python安装过程,我通常都是使用下面的命令: ./configure --enable-shared && make && make install 使用--enable-shared参数是为了一些依赖它的软件可以成功安装,比如ganglia。 今天成功安装了python2.7.2,但是运行报如下错误: python:...原创 2012-05-12 10:55:41 · 218 阅读 · 0 评论 -
股票财经API笔记
一、获取Yahoo数据 1.1 实时数据深圳交易所http://finance.yahoo.com/d/quotes.csv?s=000625.sz&f=snohgl1v000625.SZ CHANGAN AUTOMOBIL 12.4 12.8 12.4 12.69 9787354 上证交易所(API异常,目前无法获取数据):http://finance.ya...原创 2012-02-25 22:03:23 · 338 阅读 · 0 评论 -
My Django Cookbook
windows运行“django-admin.py startproject hello”创建django项目时报错“ImportError: No module named django.core” 原因:安装两个版本的python,运行py程序使用前一个版本python程序所致解决:卸载老版本python,在删除程序过程选择“repair”修复py文件管理程序,再试试就OK了。 ...原创 2011-01-25 16:04:56 · 84 阅读 · 0 评论 -
linux环境下cx_Oracle的“ImportError: No module named cx_Oracle”错误。
环境:redhat AS + python2.7 + oracle instant client + cx_oracle oracle instant client10.2.4 (linux)http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html 我下载的是:ora...原创 2011-01-03 13:20:42 · 825 阅读 · 0 评论 -
python unittest加载自己写的测试
在python unittest库中TestLoader中还有,discover是最简单的方式,另外可以直接使用nose。 def discover(): loader = unittest.TestLoader() suite1 = loader.discover('/xx/xx/xx') suite2 = loader.discover('/yy...原创 2015-12-01 22:23:36 · 283 阅读 · 0 评论 -
python new-style class和old-stype class使用super的方式
#old-style classclass Base(): def __init__(self, name): self.name = name class Child(Base): def __init__(self,name): Base.__init__(self,name) print se...原创 2015-12-01 22:27:35 · 634 阅读 · 0 评论 -
python unittest 只跑某个(某些)测试
# -*- coding: utf-8 -*- import unittestclass MyTest(unittest.TestCase): def test_method_a(self): pass def test_method_b(self): pass def test_method_c(sel...原创 2014-04-10 16:01:39 · 2972 阅读 · 0 评论 -
记录linux下安装python MySQLdb
#下载:mysql-python/https://sourceforge.net/projects/mysql-python/files/mysql-python/ #安装mysql-python解压缩tar包python setup.py build# 报错找不到mysql_config时,vi site.cfgpython setup.py ins...原创 2016-06-27 21:21:24 · 474 阅读 · 0 评论