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

Python MySqlDB 增删改数据库


下载安装MySQLdb
http://sourceforge.net/projects/mysql-python/ 好像没看到windows版本for python2.6的下载,网上搜索到一个
http://www.technicalbard.com/files/MySQL-python-1.2.2.win32-py2.6.exe
安装后import MySQLdb会出现 DeprecationWarning: the sets module is deprecated 这样一个警告,google之
原因是2.6不知sets这个模块,不过已经添加了set内置函数。找到MySQLdb文件夹的中__init__.py,注释掉from sets import ImmutableSet   class DBAPISet(ImmutableSet):添加class DBAPISet(frozenset):;找到converters.py注释掉from sets import BaseSet, Set。然后修改第45行和129行中的Set为set。
搞定。
下面开始操作的demo:
Python代码
# -*- coding: utf-8 -*-    
#mysqldb   
import time, MySQLdb   
  
#连接   
conn=MySQLdb.connect(host="localhost",user="root",passwd="",db="test",charset="utf8")   
cursor = conn.cursor()   
  
#写入   
sql = "insert into user(name,created) values(%s,%s)"  
param = ("aaa",int(time.time()))   
n = cursor.execute(sql,param)   
print n   
  
  
#更新   
sql = "update user set name=%s where id=3"  
param = ("bbb")   
n = cursor.execute(sql,param)   
print n   
  
  
#查询   
n = cursor.execute("select * from user")   
for row in cursor.fetchall():   
    for r in row:   
        print r   
  
  
#删除   
sql = "delete from user where name=%s"  
param =("aaa")   
n =&nb


相关文档:

python 初体验

windows下
1 下载python安装包, 一路下去安装
2 下载mysqldb安装
3 下载django文件, dyango-admin.py install 完成
-----如果启动后报错import error: dll load failed. 需要在site-package下增加dll: libguide40.dll  libmmd.dll  libmySQL.dll
创建应用后, manage.py 的program argument中应 ......

[python]重定向输出

  调用一个控制台程序,获取它的标准输出,或把它的标准输出重定向到界面上,这里只介绍如何获取它的标准输出,因为原理都一样的。
使用python2.5的subprocess模块来实现。
import sys
import subprocess
def RunShellWithReturnCode(command, print_output=False,
universal_newline ......

python 的函数Decorators

Decorators是python中比较难以理解的东西,当然如果你接触过java的annotation,会发现这个Decorators在语法上非常的相似,但是两者的设计动机却没什么共同点;
这里讲的python中的decorators是对python中的function/method做装饰,这些修饰仅是当声明一个函数或者方法的时候,才会应用的额外调用。
python中的decorator分 ......

Python解决文件编码问题

    前几天,小许给我一份JavaQQ的源代码,用vim打开一看,发现里面的中文都是乱码。不用说,又是可恶的编码问题,在window下的文本文件通常使用GBK或GB18030编码,而在Linux下utf-8编码则大行其道。打开——另存为肯定不是上策,上网找编码批量转换工具也不是咱勤劳勇敢的程序员的作风。自已动手 ......

用python写的抓取天气预报的脚本

用python写的抓取天气预报的脚本
http://blog.chinaunix.net/u2/82009/showart_2166843.html
从昨天开始的看关于网络抓取的东西,而且自己的用的是awesome ,所以写了这个天气预报的脚本给我的awesome,这个天气脚本直接取下来的话是七天的天气预报从中国天气网上,我后面对它做了处理,用到了我的awesome上
效果:1日星 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号