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

python写的帧分割函数

前一阵在写一个自动测试程序时需要按照特定字符对收到的数据进行帧的分割,原有要求是有每帧前后各有一个同样的特殊字符,当时估计下时间还够,想将其扩展为一个较为通用功能,即每帧数据前有各有一个特殊字符表示开始和结束,但前后这两字符可以不同,也可以只有一个(在头在尾分割效果不同),同时学习了一阵python,感觉其处理这类问题还比较合适,完成了以下初步的代码,此段代码性能上还需优化:
def frame_read(fd,head,tail,timeout):
    'return -- donot recv data return None,recv data but wrong format return [],else return data in tupe format, \
            frame_len -- each frame cmd len,'
    if fd is None or len <= 0:
        print 'fd is None or len <= 0,'
        return None
    fd_type = check_obj_type(fd)
#    print 'connect obj type is %s' % fd_type
    if fd_type == 'invalid_type':
        return None
    cur_time = time.time()
    data = ''
    lines = []
    received = False
    head_found = False
    head_len = len(head)
    tail_len = len(tail)
    temp = None
    frame_len = 512
    hex_str = ''
    while 1:
        if is_timeout(cur_time,timeout):
            print 'wait data timeout.'
            if not received:
                return None
            else:               
      


相关文档:

一篇不错的Python入门教程

原文
 http://www.hetland.org/python/instant-hacking.php
Instant Hacking[译
文]
译者: 肯定来过                                ......

Python 练习2

生成一个有N个元素的有随机整数n组成的列表,其中N和年的取值范围是(1<N<=5)
和(0<=n<100),显示这个列表的所有子集。
N个数字空有2en个子集,对于这N个数字在每个子集中来讲要么存在要么不存在,可以采用子集映射为2进制的算法。
例如[a,b]集合的子集:
空      ---- &nb ......

python下的web开发框架 Django,url配置

url配置
我们在polls这个app下创建一个
helloworld.py
from django.http import HttpResponse
def index(request):
    return HttpResponse("Hello, Django.")
修改 urls.py
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
# from django.contrib ......

Python日期和字符串的互转

用的分别是time和datetime函数
'''
Created on 2009-9-2
@author: jiangqh
'''
import time,datetime
# date to str
print time.strftime("%Y-%m-%d %X", time.localtime())
#str to date
t = time.strptime("2009 - 08 - 08", "%Y - %m - %d")
y,m,d = t[0:3]
print datetime.datetime(y,m,d)

输出当前时间 ......

python的灵活

项目需要,刚刚接触python。
今天看书看到a>b==c ,a,b,c为integer
在C/C++/C#中,a>b为boolean,不可与integer比较相等
但python a>b==c等效于((a>b)&&(b==c))
在python中的写法是a>b and b==c ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号