易截截图软件、单文件、免安装、纯绿色、仅160KB
热门标签: c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 最新文章 : Python

Python int类型插入数据库 MySQLdb

 def test2():
 32     db = util.DBUnit('mysql_ab')                                                                                                                        
 33     params = [[8000080,'8000080','8000080','8000080',8000080]]
 34     params1 = [['aaaaa','bbbbb']]
 35     sqls = ......

python中datetime的比较方法使用


python中的datetime module是专门处理时间相关内容的模块,功能很强大,但是反而显得比较复杂。
一下代码是用来求从mysql中取到的timestamp和当前时间比较,求时间差的方法
import datetime
lasttime=a.get_last_timestamp(sid=40)[-1]["last_time"] #取到timestamp
delta = datetime.datetime.now()-lasttime   #使用datetime.datetime.now()得到当前的时间,然后求时间差
if delta > datetime.timedelta(minutes=8):   #如果时间差大于 8分钟的话,(如果是8小时则是hours=8,如果是8秒则是 seconds=8)
   .....
#datetime.timedelta()这个方法比较特别,在python.org对这个class的解释是:
class datetime.timedelta([days[, seconds[, microseconds[, milliseconds[, minutes[, hours[, weeks]]]]]]])
参数可以多个一起使用,比如datetime.timedelta(hours=5,minutes=8,seconds=10),就代表5小时8分10秒
......

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 =  ......

python 的time模板翻译及说明

python 的内嵌time模板翻译及说明
一、简介
time模块提供各种操作时间的函数
说明:一般有两种表示时间的方式:
第一种是时间戳的方式(相对于1970.1.1 00:00:00以秒计算的偏移量),时间戳是惟一的
第二种以数组的形式表示即(struct_time),共有九个元素,分别表示,同一个时间戳的struct_time会因为时区不同而不同
year (four digits, e.g. 1998)
month (1-12)
day (1-31)
hours (0-23)
minutes (0-59)
seconds (0-59)
weekday (0-6, Monday is 0)
Julian day (day in the year, 1-366)
DST (Daylight Savings Time) flag (-1, 0 or 1) 是否是夏令时
If the DST flag is 0, the time is given in the regular time zone;
if it is 1, the time is given in the DST time zone;
if it is -1, mktime() should guess based on the date and time.
夏令时介绍:http://baike.baidu.com/view/100246.htm
UTC介绍:http://wenda.tianya.cn/wenda/thread?tid=283921a9da7c5aef&clk=wttpcts
二、函数介绍
1.asctime()
asctime([tuple]) -> string
将一个struct_time(默认为当时时间),转换成字符串
Convert a time tuple to a string, e.g. 'Sat Jun 06 ......

在Windows下使用Python编程

一、使用Python需要知道的
在 Windows 上,安装 Python 有两种选择。
1、ActiveState 制作的 ActivePython 是专门针对 Windows 的 Python 套件,它包含了一个完整的 Python 发布、一个适用于Python 编程的 IDE 以及一些 Python的 Windows 扩展,提供了全部的访问 Windows APIs 的服务,以及 Windows注册表的注册信息。虽然 ActivePython 不是开源软件,但它可以自由下载。ActivePython 是我学习Python 时使用过的 IDE。除非有别的原因,我建议您使用它。可能的一个原因是:ActiveState 通常要在新的 Python 版本发布几个月以后才更新它的安装程序。如果您就需要 Python 的最新版本,并且 ActivePython 仍然落后于最新版本的话,您应该直接跳到在 Windows 上安装 Python 的第二种选项。
2、第二种选择是使用由 Python 发布的 “官方” Python 安装程序。她是可自由下载的开源软件,并且您总是可以获得当前 Python 的最新版本。
二、安装  ActivePython
在Windows安装ActivePython的方法如下:
1、从 http://www.activestate.com/Products/ActivePython/ 下载 ActivePython 。我的下载地址为:http://downloads.activestate.com/ActivePython/releases/2. ......

Python获取操作系统版本信息

    最近,想在我的YouMoney(http://code.google.com/p/youmoney/)里面增加提取用户操作系统版本信息。比如windows用户,可能要返回Windows XP ,或者Windows 2003, 苹果用户应该返回Mac OS X 10.5.8。用了很多办法,包括在mac系统里调用系统命令,取环境变量,等等。最后无意发现,原来python里里面有个platform模块就可以干这件事情。省事啊!
     mac上这么干
localhost:~ apple$ python
Python 2.5.1 (r251:54863, Jun 17 2009, 20:37:34)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.mac_ver()
('10.5.8', ('', '', ''), 'i386')
>>> platform.version()
'Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386'
>>> platform.platform()
'Darwin-9.8.0-i386-32bit'
>>> platform.system()
'Darwin'
>>>
 基本上用platform.platform()就足够了。 ......
总记录数:695; 总页数:116; 每页6 条; 首页 上一页 [31] [32] [33] [34] 35 [36] [37] [38] [39] [40]  下一页 尾页
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号