python常用库类
分类 | 名称 | 用途 |
---|---|---|
科学计算 | Matplotlib | 用python实现的matlib三方库,用于绘制高质量的数学二维图形 |
科学计算 | SciPy | 基于python的matlab实现,旨在实现matlab的所有功能 |
科学计算 | NumPy | 基于python的科学计算第三方库,提供了矩阵、线性代数、傅里叶变换等 |
GUI | PyGtk | 基于Python的GUI程序开发GTK+库 |
GUI | PyQt | y用于Python的QT开发库 |
GUI | WxPython | Python下的编程框架,与MFC架构相似 |
GUI | Tkinter | Python自带的界面编程包 |
其他 | BeautifulSoup | 基于Python的HTML/XML解析器,简单易用 |
其他 | PIL | 基于Python的图像处理库,功能强大,对图像格式支持广泛 |
其他 | MySQLdb | 用于链接Mysql 数据库 |
其他 | cElementTree | 高性能的xml解析器,python2.5之后包含该模块 |
其他 | PyCame | 基于Python的多媒体开发和游戏开发模块 |
其他 | Py2exe | 将Python转化为exe文件 |
其他 | pefile | windows PE 文件解析器 |
threading 模块
threading.Thread
threadong 中的Thread类,可以使用它来创建多线程。
具体使用方法是创建一个threading.Thread对象。
#conding = utf-8
import threading, time
count = 0
class MyThread(threading.Thread):
def __init__(self,threadName):
super(MyThread,self).__init__(name = threadName)
def run(self):
global count
for i in range(100):
count = count + 1
time.sleep(0.3)
print(self.getName(),count)
for i in range(2):
MyThread("MyThreadName" +str(i)).start()
threading.Lock
使用lock.acquire() 和lock.release()包围的代码将进行同步操作,即此代码块执行完毕后,才能进行线程切换。
#coding = utf-8
import threading , time , random
count = 0
class MyThread(threading.Thread):
def __init__(self,lock,threadName):
super(MyThread,self).__init__(name = threadName)
self.lock = lock
def run(self):
global count
self.lock.acquire()
for i in range(100):
count +=1
time.sleep(0.3)
print(self.getName(),count)
self.lock.release()
lock = threading.Lock()
for i in range(2):
MyThread(lock,"MythreadName:" + str(i)).start()
threading.join
join类是threading中用于阻塞当前主线程的类,其作用是阻塞当前所用线程,直到被调用的线程执行完毕或者超时。
import threading,time
def doWaiting():
print('start waiting:', time.strftime('%S'))
time.sleep(3)
print('stop waiting', time.strftime('%S'))
thread1 = threading.Thread(target=doWaiting)
thread1.start()
time.sleep(1)
print('start join')
thread1.join()
print('join end')