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

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 处理字节


zz from: http://blog.sina.com.cn/s/blog_4b5039210100f1tu.html
原文有点小错误,改了一点点。
我们知道python只定义了6种数据类型,字符串,整数,浮点数,列表,元组,字典。但是C语言中有些字节型的变量,在python中该如何实现呢?这点颇为重要,特别是要在网络上进行数据传输的话。

python提供了一个struc ......

python安装之setuptools

David 在本文中将带领我们了解一下 setuptools 框架,它是 Python Enterprise Application Kit(PEAK)的一个副项目。 setuptools 替换了标准的 distutils 库,并为 Python 添加了版本化的包和依赖性管理。Perl 用户比较熟悉 CPAN,而 Ruby 用户则比较熟悉 Gems;引导 setuptools 的 ez_setup 工具和随之而生的扩展后的 eas ......

python的C、c++扩展

python的C、c++扩展
http://blog.chinaunix.net/u3/110228/showart_2148725.html
python的强大不仅表现在其功能上,而且还表现在其扩展能力上。
使用C/C++很容易编写python的模块,扩展python的功能。
同时将性能要求比较高的代码使用C/C++编写,能更好的弥补
脚本语言执行速度慢的缺陷。
1. python的C语言扩展
1.1 ......

Python int类型插入数据库 MySQLdb

 def test2():
 32     db = util.DBUnit('mysql_ab')                                    &nb ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号