易截截图软件、单文件、免安装、纯绿色、仅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下的web开发框架 Django,创建项目

解压django,然后到其目录下安装
前提是你安装好python.并将其配置到环境变量中,然后去django的压缩文修的下,执行以下倒命令
python setup.py install
1.创建project
首先我们打开cmd, 定位到希望新建工程的目录下, 任意目录均可. 然后键入如下命令:
django-admin.py startproject hello其中hello为新工程目录文件名 ......

Python文件的读写

相比java而言,Python用几行代码就可以代替java十来行的代码,真的非常不错
'''
Created on 2009-9-2
@author: jiangqh
'''
# file create and write
context = '''hello world
hello china '''
f = file("hello.txt",'w')
f.write(context)
f.close()
文件创建
#use readline() read file
f = o ......

转段Python代码

#==================================================
import wx
import wx.media

class MyFrame(wx.Frame):
def __init__(self,parent,title):
wx.Frame.__init__(self,parent,-1,title,pos=(150,150),size&;nbsp;=(640, 480),style=wx.MAXIMIZE_BOX|wx.SYSTEM_MENU|wx.CAPTION|wx.CLOSE_BOX| ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号