易截截图软件、单文件、免安装、纯绿色、仅160KB

关于Python正则表达式的区分大小写的问题

最近在用Python处理一些数据,数据需要存储到MySQL数据库中,采用MySQLdb来进行数据库的操作,但是被一个问题困扰了很久。在打开数据库的时候MySQLdb.connect(self.host, self.user, self.password, self.database, port=self.port)出异常,而且异常出现的位置非常奇怪。
出现在converters.py 164行
from decimal import Decimal
进去之后发现出错的位置在decimal.py文件中5833行出错
import re
_parser = re.compile(r"""        # A numeric string consists of:
#    \s*
    (?P<sign>[-+])?              # an optional sign, followed by either...
    (
        (?=\d|\.\d)              # ...a number (with at least one digit)
        (?P<int>\d*)             # having a (possibly empty) integer part
        (\.(?P<frac>\d*))?       # followed by an optional fractional part
        (E(?P<exp>[-+]?\d+))?    # followed by an optional exponent, or...
    |
        Inf(inity)?              # ...an infinity, or...
    |
        (?P<signal>s)?           # ...an (optionally signaling)
        NaN                      # NaN
        (?P<diag>\d*)            # with


相关文档:

Python MySQLdb 查询返回字典结构


Python MySQLdb 查询返回字典结构 smallfish
MySQLdb默认查询结果都是返回tuple,输出时候不是很方便,必须按照0,1这样读取,无意中在网上找到简单的修改方法,就是传递一个cursors.DictCursor就行。
默认程序:
import MySQLdb
db = MySQLdb.connect(host = 'localhost', user = 'root', passwd = '123456', d ......

使用C语言扩展Python(一)

开发环境:Ubuntu9.10,python2.6,gcc4.4.11,ubuntu下的python运行包和开发包是分开的,因此需要在新利得里面安装python-all-dev,从而可以在代码中引用python的头文件和库。2.下面是一个最简单的可以供python调用的c扩展模块,假设c程序文件名为foo.c:代码#include <Python.h>
static PyObject* foo_b ......

分享一个简单的python模板引擎


#coding:utf-
8
  
__author__="sdm"
  
__author_email='sdmzhu3@gmail.com'
  
  
__date__ ="$2009-8-25 21:04:13$"
  
  
''
'  
pytpl 类似
php的模板类  
  
&nbs ......

Python三目运算,and or陷阱

在C语言中,三目运算经常用到(cond?a:b),非常的简洁,而在Python中不支持这种语法。
但是,可以用Python中and or来实现(这里是有陷阱的,下面会讲到)
我们来看下面几个表达式
>>> False
or 1
1
>>> False
or 0
0
>>> True or
0
True
>>> True
and 1
1
>> ......

使用C语言扩展Python(三)

上一篇中我们已经了解如何在Python程序和C模块之间进行值的相互传递,现在我们来进入实作阶段,看看如何将一个C语言开发的开源mp3编解码库LAME包装为一个Python下可以使用的扩展模块。首先去http://lame.sourceforge.net/download.php下载LAME的源代码,然后切换到root用户编译源代码,./configure
make
make instal ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号