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秒
相关文档:
列表方法:
方法
说明
append( item )
在列表末尾插入(item )
count( element )
返回element在列表中出现的次数
extend( newlist )
将newlist的元素插入列表末尾
index( element )
返回element在列表中的索引,如果不存在,则引发ValueError异常
insert( index , item )
在index ......
zz from: http://blog.sina.com.cn/s/blog_4b5039210100f1tu.html
原文有点小错误,改了一点点。
我们知道python只定义了6种数据类型,字符串,整数,浮点数,列表,元组,字典。但是C语言中有些字节型的变量,在python中该如何实现呢?这点颇为重要,特别是要在网络上进行数据传输的话。
python提供了一个struc ......
David 在本文中将带领我们了解一下 setuptools 框架,它是 Python Enterprise Application Kit(PEAK)的一个副项目。 setuptools 替换了标准的 distutils 库,并为 Python 添加了版本化的包和依赖性管理。Perl 用户比较熟悉 CPAN,而 Ruby 用户则比较熟悉 Gems;引导 setuptools 的 ez_setup 工具和随之而生的扩展后的 eas ......
软件准备:
1.eclipse开发包,下载地址:http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/galileo/SR2/eclipse-java-galileo-SR2-win32.zip
2.pydev插件,下载地址:http://sourceforge.net/projects/pydev/files/pydev/Pydev%201.5.4/org.python.pydev.feature-1.5.4.2010011921 ......
1.c调用python:
实例代码:
main.c调用test.py的
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//main.c
#include <windows.h>
......