易截截图软件、单文件、免安装、纯绿色、仅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 pyserial 串口

用python写了个最简单的读串口的程序,因为工作中经常需要读串口
放原始代码
import serial
ser = serial.Serial('com3',baudrate=115200, bytesize=8,parity='N', stopbits=1,xonxoff=0, timeout=1)
while( True ):
    a = ser.read(100)
    print a
用完需要ser.close(),否则其他串口就无法再使用该串口,因为该串口会一直被占用。 ......

python 多继承

 from: http://www.cnblogs.com/dahuzizyd/archive/2005/03/01/111006.html
python支持面向对象的编程风格,这里主要说说python中的多继承:
下面的代码使用python2.4,安装后使用idle的IDE开发环境(说是IDE ,比起delphi,VS.net等简单得太多了)
从File-New菜单建立一个.py文件,写下面的代码:
class SuperClass:
    def sample(self):
        print 'SuperClass'
class SubClass(SuperClass):
    pass
sub = SubClass()
sub.sample()
要先保存,再按F5执行,在idle的主窗口显示:
>>> ================================ RESTART ================================
>>>
SuperClass
>>>
子类调用了父类的sample方法,现在修改代码,如下:
class SuperClass:
    def sample(self):
        print 'SuperClass'
class SuperClass1:
    def sample(self):
        print 'SuperClass1'
class SubClass(SuperClas ......

python 多继承(2)

from:  http://www.chinesepython.org/pythonfoundry/tut2.3/tmp/multiple.html
9.5.1 多继承 Multiple Inheritance
Python supports a limited form of multiple inheritance as well. A class definition with multiple base classes looks as follows:
Python同样有限的支持多继承形式。多继承的类定义形如下例:
class DerivedClassName(Base1, Base2, Base3):
<statement-1>
.
.
.
<statement-N>
The only rule necessary to explain the semantics is the resolution rule used for class attribute references. This is depth-first, left-to-right. Thus, if an attribute is not found in DerivedClassName, it is searched in Base1, then (recursively) in the base classes of Base1, and only if it is not found there, it is searched in Base2, and so on.
这里唯一需要解释的语义是解析类属性的规则。顺序是深度优先,从左到右。因此,如果在 DerivedClassName (示例中的派生类)中没有找到某个属性,就会搜索 Base1 ,然后(递归的)搜索其基类,如果最终没有找到,就搜索 Base2,以此类推。
(To s ......

python中使用方便的LIST对象

最近对python产生了兴趣,于是从网上下载了基本PYTHON的书和文档,开始了PYTHON的学习,发现PYTHON中的list对象的功能实在是非常强大,编程起来比其他的程序语言对列表的操作要方便的多。
在python中定义一个列表只需要如下语句
li = ["a","b","c","d"]
list有许多的函数可以用来进行对列表的操作,如extend,append,insert,remove,pop
如果要向列表中添加项目很方便,既可以单独添加一个项目,也可以添加整个列表li.append("f") 添加一个项目 a,b,c,d,f
li.extend(["f","g"]) 将另一个列表添加到列表末尾 a,b,c,d,f,g
还可以将项目添加到指定的位置
li.insert(2,"f") 将"f"添加到第二个位置 a,b,f,c,d,e
删除元素也可以通过函数进行
remove:删除元素
>>> li
['a', 'b', 'c']
>>> li.remove("a")
>>> li
['b', 'c']
可以直接将要删除的元素作为参数传递给函数,则会从列表中删除此元素
pop 是删除列表中的最后一个元素,并返回它的值
>>> li.pop()
'c'
python中的list和C语言中的数组一样,里边的元素都是从零开始计数的,同时在python中也可以采取同C语言获取数组元素同样的方法
来获取列表中的元素
li[0]  &n ......

最简单的 python 多线程示例

import time,thread
def test(a,b):
for i in range(a,b):
       time.sleep(1)
       print i
def start():
thread.start_new_thread(test,(1,1001))
thread.start_new_thread(test,(1000,2001))
if __name__=='__main__':
start()
......

python 获取E

E-mail主要由邮件头和邮件体两部分组成。
邮件头中的内容和我们寄信时写在信封上的内容大同小意,当然这里也包含了很多路过的“邮局”的信息了。
邮件体中的内容就是我们写的信或者包裹。
python自身包含了email模块处理可以快速的处理E-mail中的信息
import email
#打开一个文件
fp = open('email.eml', 'r')
#创建email实例
msg = email.message_from_file(fp)
#现在我们就可以很简单的取出我们想要的邮件头信息
subject = msg.get('subject')
from = msg.get('from')
to = msg.get('to')
现在我们已经得到了邮件的主题,发件人和邮件人的信息
可是我们怎么取得邮件中正文信息和附件信息呢?
这些信息我们就需要遍历邮件内容来获取了。
for part in msg.walk():
    if part.is_multipart():
            continue
    #获取内容类型
    content_type = part.get_content_type()
    #text/plain类型说明是文本,有时邮件格式不规范会写为text
    if ('text/plain' == content_type
  & ......
总记录数:695; 总页数:116; 每页6 条; 首页 上一页 [107] [108] [109] [110] 111 [112] [113] [114] [115] [116]  下一页 尾页
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号