含有章节索引的中文 文章模板
::-- hoxide [2005-04-09 06:08:44]
Contents
文本处理
RegExpInPython - 正则表达式
ReportLab
- 简述:用于生成PDF文档
- 能力: 生成PDF文档, 合并PDF文档, 将HTML导入到PDF文档中.
- 例子:
1 from reportlab.pdfgen import canvas
2 from reportlab.lib.units import inch
3
4 font = "Helvetica"
5 font_size = 26
6 text = "Hello, world"
7 x = 5.0 * inch
8 y = 8.0 * inch
9 destination_file = "/tmp/first.pdf"
10
11 my_canvas = canvas.Canvas(destination_file)
12 my_canvas.setFont(font, font_size)
13 my_canvas.drawRightString(x, y, text)
14 my_canvas.save()
编译工具
科学计算软件
NumPy
简述:提供对序列的快速处理 - NumPy
官方站点: http://numpy.scipy.org
第一代矩阵操作模块 Numeric 又称为 NumericalPython
第二代矩阵操作模块 Numarray
关于NumPy, Numeric, Numarray 之间的关系,请看History of SciPy
SciPy
基于wxPython的plt绘图模块
- 依赖的包: wxPython, gui_thread, scipy
测试环境: windows2000, python2.3.3, SciPy_complete-0.3.2 Numeric-23, wxPython2.5-win32-unicode-2.5.3.1
- 存在的问题, 按照说明书无法正确启动独立的wxPython线程. 解决如下:
1 >>> import gui_thread
2 >>> gui_thread.start(use_main=1)
3 <wxPython imported>
4 >>>
5 >>> from scipy import plt
6 >>> img = plt.lena()
7 >>> plt.image(img)
8 <type 'array'> ['__copy__', '__deepcopy__', 'astype', 'byteswapped', 'copy', 'iscontiguous', 'itemsize', 'resize', 'savespace', 'spacesaver', 'tolist', 'toscalar', 'tostring', 'typecode']
9 <scipy.plt.wxplt.plot_frame; proxy of C++ wxFrame instance at _d8c21602_p_wxFrame>
10 >>>
即用gui_thread.start(use_main=1)来启动独立的wxPython线程.
与GIS(地理信息系统)有关的python库和程序
有关库的链接
因为我玩的是GIS,所以提供几个GIS有关的python程序以及库吧(和GIS有关的python绑定实在太多了!去这里还有这里搜索一下一大把,下面推荐几个吧,这里是几个最近我正在玩的)。
ogr (OGR Simple Feature Library )
- 一个对GIS矢量数据进行读取和操作的库,用C/C++写的,有python接口
gdal (Geospatial Data Abstraction Library)
- 一个对栅格空间数据进行读取的库,用C/C++写的,有python接口
geos (Geometry Engine Open Source)
- 一个对矢量图形进行叠加分析的操作库,有python接口
FWTools (Open Source GIS Binary Kit for Windows and Linux)
- 一个GIS的整套工具(程序,非库),用python写的。
下面是python主页科学和数值计算版的关于GIS的记录
- Thuban
- 是一个GIS成品,不过太老了,只适合python2.3
- Python Cartographic Library, News from Import Cartographic,
- 是一个集成的GIS实用库,我没有玩过,不发表评论。
我的学习笔记
多媒体
含有章节索引的中文 文章模板
::-- hoxide [2005-07-29 19:19:46]
Contents
PIL
简述 Python的图像处理工具集, 功能比较很强大, 配合Numarray使用, 可以做图像处理.
官方页面: http://www.pythonware.com/products/pil/
例子
用PIL+Numarray处理图像
1 import Image
2 from numarray import array
3 from Gnuplot import Gnuplot
4 from math import ceil
5
6 imsize = (512, 512)
7 drt = (( 0, 1), ( 1, 1), ( 1, 0), ( 1, -1),
8 ( 0, -1), ( -1, -1), ( -1, 0), ( -1, 1))
9 drt = array(drt)
10
11 def dofile(file, z):
12 im = Image.open(file)
13 a = im.getdata()
14 a = array(a).resize(*imsize)
15 r = list()
16 for i in xrange(imsize[0]):
17 for j in xrange(imsize[1]):
18 for dx, dy in drt:
19 if ( i+dx>=0 and i+dx < imsize[0] and
20 j+dy>=0 and j+dy < imsize[1] and
21 a[i][j] != a[i+dx][j+dy]):
22 r.append((i, j, z))
23 return r
24
25 def ddfile(file, z):
26 im = Image.open(file)
27 a = im.getdata()
28 a = array(a).resize(*imsize)
29 r = getedge(a, z)
30 return r
31
32 def getedge(a, z):
33 imsize = a.shape
34 r = list()
35 try:
36 for i in xrange(imsize[0]):
37 for j in xrange(imsize[1]):
38 if (a[i,j] == 0):
39 #print i,j
40 raise StopIteration
41 except StopIteration:
42 r.append((i,j, z))
43 if len(r)==0 :
44 return None
45 nd = 0
46 x, y = i, j
47 r.append((z, x, y))
48 while True:
49 for d in xrange(8):
50 dd = (nd+d) %8
51 if a[x+drt[dd][0], y + drt[dd][1]] == 0:
52 r.append((x, y, z))
53 x, y = (x, y) + drt[dd]
54 nd = (dd + 4 +1) %8
55 break
56 if x == i and y == j:
57 break
58 return r
59
60
61 def out(ofp):
62 np = 30
63 for i in xrange(100):
64 fname = 'abmp/'+str(i)+'.bmp'
65 r = ddfile(fname, i)
66 l = len(r)
67 step = (l-1.0)/np
68 for i in xrange(np):
69 x, y, z = r[int(step*i)]
70 ofp.write("%d\t%d\t%d\n"%(z, y, x))
71 x, y, z = r[0]
72 ofp.write("%d\t%d\t%d\n"%(z, y, x))
73 ofp.write("\n")
74
75 def pointplot():
76 g = Gnuplot()
77 g('set pm3d')
78 g('set hidden3d')
79 g('splot [0:500] [0:500] [0:500] "oo.dat" w l')
80 raw_input("Press Enter to continue...")
81
82
83 if __name__ == '__main__':
84 ofp = open('oo.dat', 'w')
85 out(ofp)
86 ofp.close()
87 pointplot()
pygame
- 简述:用于游戏制作 - pygame
- 能力:有完备的控制、声音、显示模块,支持bmp,png等多种图像格式,自动载入Alpha通道,能显示复杂特效。
- 缺点:图像必须读入surface后显示,占用内存多,不适合制作大型游戏
官方站点: http://www.pygame.org/
数据库工具
SQLObject
- 简述:用于方便访问数据库,不需要写一行SQL语句
- 能力:
- 缺点:
请大家不断补充