Thursday, February 16, 2006
MoinMoin@Ubuntu-5.10
Escape Squences@RegExp
通常Escape sequence都是表示特殊字元,如$, ?, ^...,所以在python中,要用\$, \?, \^,分別來表示,但是backquote本身該如何表示呢,\\即可,所以在regexp中,要寫成r'\\',雖然己經用了raw表示法,但仍然還需再加一個backquote。
為了要找出最適合的善歌,用以下的程式來列舉出所有的mp3,然後再找出適合的歌曲。
from sys import stdin
from re import findall
data=stdin.read()
Files=findall(r'\\+\\(.*).mp3, data)
for file in Files:
if not Temp.count(file): Temp.append(file)
for file in Temp: print file
Friday, February 03, 2006
Tex2Png
LaTeX可以非常方便地,將TeX語法轉成數學圖形,於是模仿TextoGif的作法,且結合MoinMoin下的latexparser的圖形製作方式,自己改成了Tex2Png,主要是可以從stdin讀入latex的數學指令,存成Temp.tex,然後再裁切成png的圖檔,改寫的主要的步驟如下:
Tex.Tmpl內容如下:
\begin{eqnarray*}
$TexData
\end{eqnarray*}
- 如stdin讀入eqnarray的指令,將中間的字串換成要顯示的數學指令。
- 進入/tmp目錄夾
- 使用latex -interaction=batchmode Temp.tex的指令,作出Temp.dvi的暫存檔。
- dvips -E Temp.dvi -o Temp.ps,作出Temp.ps檔
- convert -crop 0x0 -density 120x120 Temp.ps Temp.png,作出png的圖檔,同時也裁切圖檔,避免圖檔空白的地方太多
現在要再深入的是
- dvips的指令
- gs的指令: 因為textogif是使用gs -dNOPAUSE -r -sQutputFile=- -sDEVICE=pbmraw Temp.ps來達成
Python Image Library
想要用python來處理影像,PIL(Python Imaging Library),是蠻不錯的選擇。
PIL來自http://effbot.org/downloads是在Python社群中,專門處理圖片的Library,它有2種release版本,一為source,另一為binary,最新的版本分別如下:
如果下載source,安裝後在$Imaging-xx.yy/Docs的目錄中,可以看到豐富的說明文件,及範例程式,文件內容包含了:系統需求、如何去編譯、安裝...。
- 系統需求
- JPEG and/or PNG
- PNG and ZIP:zlib
- TrueType/OpenType:freetype.org
- 編譯及安裝
a. 先作出libImaging/ImConfig.h
[samuel@IBM Imaging-1.1.4]$ cd libImaging
./configure ===> Makefile
make ===> ImConfig.h
b. 安裝
[samuel@IBM Imaging-1.1.4]$sudo python setup.py install
c. 測試
[samuel@sl304 ~]$ python
Python 2.4 (#9, Jan 22 2005, 13:05:42)
[GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-42)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
>>>
如果沒有錯誤訊息,表示安裝成功。- 範例
1. 簡單測試
>>> import Image
>>> im = Image.open("lena.ppm")
>>> print im.format, im.size, im.mode
PPM (512, 512) RGB
>>> im.show() #using 'xv', handy for debugging and testing
2. 開檔
import Image
im=Image.open('Conficius.gif')
im.crop((360,150,700,745)).save('Conficius.png')
3. Crop Images
box = (100, 100, 400, 400) #cropping
region = im.crop(box)
region = region.transpose(Image.ROTATE_180) #box processed and pasted back
im.paste(region, box)
4. Rolling an image
def roll(image, delta):
"Roll an image sideways"
xsize, ysize = image.size
delta = delta % xsize
if delta == 0: return image
part1 = image.crop((0, 0, delta, ysize))
part2 = image.crop((delta, 0, xsize, ysize))
image.paste(part2, (0, 0, xsize-delta, ysize))
image.paste(part1, (xsize-delta, 0, xsize, ysize))
return image
5. Geometrical Transforms
out = im.resize((128, 128))
out = im.rotate(45) # degrees counter-clockwise
out = im.transpose(Image.FLIP_LEFT_RIGHT)
out = im.transpose(Image.FLIP_TOP_BOTTOM)
out = im.transpose(Image.ROTATE_90)
out = im.transpose(Image.ROTATE_180)
out = im.transpose(Image.ROTATE_270)
GoogleTalk in Python
Howto to Talk with GoogleTalk in Python
範例程式
import xmpp
login = 'Your.Login' # @gmail.com
pwd = 'YourPassword'
cnx = xmpp.Client('gmail.com')
cnx.connect( server=('talk.google.com',5223) )
cnx.auth(login,pwd, 'botty')
cnx.send( xmpp.Message( "YourFriend@gmail.com" ,"Hello World form Python" ) )
urllib2結合re的應用
如果你有個list的結構如下:
L=['index.html', 'preface.html', 'd0e34.html', 'd0e37.html', 'd0e44.html', 'consul ting.html', 'consulting.html', 'preface.html', 'preface.html', 'Audience.html', 'ChangesThirdEd.html', 'Acknowledgement.html', 'ToolsPart.html', 'intro.html', ' intro.html', 'OnlineResources.html', 'XSLprocessors.html', 'XSLprocessors.html', 'FOprocessors.html', 'Portability.html', 'ToolsSetup.html', 'ToolsSetup.html', 'ToolsSetup.html', 'ToolsSetup.html', 'ToolsSetup.html', 'InstallStylesheets.htm l', 'InstallingAProcessor.html']
也就是說,有些值是duplicated,這時該怎何將此list的資料結構purified?
這可以應用在存取網路文件資料的範例中,例如在http://www.sagehill.net/docbookxsl,上頭有很多有用的文章,但它是以html的方式存在,並不是單一的檔案(如pdf的格式),這對於如果想要讀取文件,但總是需要到同一網站來進行online方式的閱讀,最好的方式是將之全數下載,但對於python,要用何方式,來作到呢?
利用urllib2中的urlopen可以幫我們作到這一點。
#!/usr/bin/env python
from urllib2 import urlopen
from re import findall
from os import system, stat
def Purified(List):
Temp=[]
for value in List:
if not Temp.count(value): Temp.append(value)
return Temp
def RetDocxsl():
try:
SageFlag=stat('sagehill')
if not SageFlag[6]:
data=urlopen('http://www.sagehill.net/docbookxsl/').read()
Webpages=findall('(.*?.html)',data)
Webpages=Purified(Webpages)
for page in Webpages:
system('wget --no-clobber http://63.249.72.176/docbookxsl/%(page)s'%vars())
#system('wget --no-clobber http://www.sagehill.net/docbookxsl/%(page)s'%vars())
else:
data=open('sagehill').read()
Webpages=findall('(.*?.html)',data)
for page in Webpages:
system('wget --no-clobber http://63.249.72.176/docbookxsl/%(page)s'%vars())
except:
data=urlopen('http://www.sagehill.net/docbookxsl/').read()
open('sagehill'),write(data)
Webpages=findall('(.*?.html)',data)
for page in Webpages:
system('wget --no-clobber http://63.249.72.176/docbookxsl/%(page)s'%vars())
if __name__=='__main__':
RetDocxsl()
以上的程式碼,是利用urlopen將網址內容(index.html)讀取,並將文件內容存取成檔案(檔名為sagehill,方便下次來進行存取),然後用re來parse所需要的文件網址位置。
利用wget來捉取檔案(--no-clobber選項的目的是,如果系統內有重複的檔案,就不要捉取具有相同檔名的文件,wget會略過,以利捉取檔案的速度)。
若是不用--no-clobber的選項,就要讓List中的檔案項目單一化(purified),這一點也可以化作讀者的作業習題?!
此時可以利用getopt的方法,讓網址由getopt的選項,傳入去程式裡,使得程式本身更有彈性,加上利用urlparse,使得網址可以方便地找出來。這方面的便利性,可以作為程式改良的思考方向。
延伸問題: 如果是在windows中,沒有wget這個方便的util,如何用python幫忙將網頁資料取回??
>>> urlparse.urlparse('http://www.sagehill.net/docbookxsl/')
('http', 'www.sagehill.net', '/docbookxsl/', '', '', '')
Character reference轉換
如果在文件檔中,有一些是屬於character reference的文字如下:
<gentext key="Abstract" text=" x6458; x8981;"/>那要如何去處理這些屬於character numeric notation的文字呢,利用python中的模組可以幫忙。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os,sys,re
from optparse import OptionParser
class XmlParser:
def __init__(self, XmlFile):
self.XmlData=open(XmlFile).read().decode('utf8')
def PrintOut(self):
from xml.dom.minidom import parseString
self.XmlObj= parseString(self.XmlData)
self.XmlStr=self.XmlObj.toxml(encoding='utf8')
print self.XmlStr
if __name__=='__main__':
usage='%prog [option]'
parser=OptionParser(usage=usage,version='%prog, Reversion 0.1')
parser.add_option('-X','--Xml',help='-X file.xml, parse XML')
options,args=parser.parse_args()
if len(sys.argv)==1: parser.print_help();raise SystemExit
if options.Xml:
xmlParser=XmlParser(options.Xml)
xmlParser.PrintOut()
利用xml模組中的minidom,可以方便地將character reference文字轉換,google中相關的網站連結資料很豐富:
時鐘追趕問題
對於python可以運用在教學情境裡,可以用一個很有趣的例子,來作這方面的應用,「時鐘追趕問題」:如果時間在二點到三點鐘之間,分針與時針什麼時候重合?
「重合」表示2針會成為一直線,這代表會有2次重疊的時刻,一次是短針和長針同方向重合在一起,另一次則是2針反方向而成為一直線的狀態。
現在想要更一般性地來表示這個問題,如果時刻是在h時m分的時候,請問短針、長針重合的時刻為何?
我們將證明,如果時間為h時m分,和時間為h時整點,其重合的時間是一致的。
證明:假設x為重合的時間,ExtraTime為額外需要的時間,如果題目是要2針夾角成Theta度,則換算成為Theta/6分;因為分針的速度為時針的12倍,所以下列式子A成立。
x-m=t t=t/12+ExtraTime+(5h+m/12)-m <=== 式子A x=(60h+12*ExtraTime)/11
ExtraTime為0的表示同方向重合,為30則表示反方向重合的狀態,剛好與時針在整點時,所算出的結果是一致的。
import sys
from optparse import OptionParser
from math import modf
def SynClockTime(*args):
Hour, Min=args
MinAngle, HourAngle=Min*6, Hour*30+Min/2.
if HourAngle>MinAngle: #MinAngle over the HourAngle
for ExtraMin in (30, 60):
AlignMin=(60*Hour+ExtraMin*12)/11.
Sec, Min=modf(AlignMin)
Sec, Min=Sec*60, int(Min)
if Min<60: Min%=60; Hour+=1
print 'The next alignment is= %(Hour)s:%(Min)s:%(Sec)s'%vars()
else:
for ExtraMin in (0, 30):
AlignMin=(60*Hour+ExtraMin*12)/11.
Sec, Min=modf(AlignMin)
Sec, Min=Sec*60, int(Min)
if Min>60: Min%=60; Hour+=1
print 'The next alignment is= %(Hour)s:%(Min)s:%(Sec)s'%vars()
if __name__=='__main__':
usage='%prog [option]'
parser=OptionParser(usage=usage,version='%prog, Reversion 0.1')
parser.add_option('-T','--Time',nargs=2,type='int',help='-T Hour(24-format) Min')
options,args=parser.parse_args()
if len(sys.argv)==1:parser.print_help();raise SystemExit
if options.Time: SynClockTime(*options.Time)
程式碼分為2個情形,如果時針所走的角度比較大,則在同一整點時刻,會有2次重合的時間,如果分針所走的角度較大,則在同一整點及下一整點時刻,分別都有一次的重合時刻。
這個問題,可以幫我們理解,如何用python來表示,追趕問題中所需的數學式子。
延伸問題:
是否可以算至重合時間精確到秒?亦即為找出"hour時min分sec秒",2針重合。
用python教數學
Teaching Math with Python
Web Framework Python News Getting Serious About Series A Mathematical Canvas a free, cross-platform ray tracing package, plus scripting language http://www.rwgrayprojects.com/synergetics/s04/figs/f1930.html 419.30figurebiblio
http://www.pythonchallenge.com/ 是一個好玩的電腦程式語言謎題網站,大部分題目不限定用 Python,你可以用 Python 來解題過關,也可以使用其他程式語言來 *挑戰 Python* 。 . http://www.ibiblio.org/g2swap/byteofpython/read A Byte of Python http://www.ibiblio.org/obp/pyBiblio/ 最近試著透過xmlrpc的介面來發佈Blog的文章 恩,傳送文字的部份成功了 現在,想要上傳圖片,不過都一直弄不好 然後又看不懂問題出在哪邊 有人可以幫忙的嗎?? code: import xmlrpclib, sys, base64 login="cute0185" password="aa0654" s = xmlrpclib.Server('http://210.71.14.54/plog/xmlrpc.php') image64 = xmlrpclib.Binary() image64.data = file('PythonTest01.jpg','rb').read() length = len(str(image64)) print s.metaWeblog.newMediaObject(1,login,password,{'type':'image/jpeg','bits':image64}) 請問兩個問題:cgi程式和Unicode問題 Posted by kayjean at 2005-10-30 20:39 * Quote * Reply * * 1.原本的系統主要是c/c++系統,為了web使用, 曾經使用apache-module寫cgi介面程式,不過 覺得實在是太麻煩了.想使用比較簡單的script程式 2.我"感覺"python不錯,可是中文書少的很誇張, 目前正在看 http://www.byteofpython.info/ 可是它並沒有提到有關cgi程式需要的東西 3.我本來想買 Web Programming in Python: Techniques for Integrating Linux, Apache and MySQL 或是 Python Web Programming 可是一看都是2001年的書,又擔心版本差太多 4.請問哪裡有python/cgi的範例或是介紹呢 5.另外,請問python支援unicode(尤其是cgi部分)的狀況如何呢 謝謝 kayjean Member Posts: 2 ‧ Re: 請問兩個問題:cgi程式和Unicode問題 Posted by marr at 2005-10-31 00:16 * Quote * Reply * * 1. python 與 C/C++ 和 web 的結合都很輕鬆,支援完整。 2. keyword: python cgi tutorial for google 找到 http://www.cs.virginia.edu/~lab2q/ 3. 如果是入門學習的話,先看線上文件很可能就足夠了,純粹使用 CGI 的部份功能,python 版本問題可能不太。 4. http://www.awaretek.com/tutorials.html 可參考 5. http://ibiblio.org/obp/py4fun/unicode/unicode.html 可參考 marr Manager Posts: 15 ‧ Re: 請問兩個問題:cgi程式和Unicode問題 Posted by kayjean at 2005-10-31 00:37 * Quote * Reply * * 真是很感謝歐,我會盡快嘗試的 也希望我能盡快熟悉PYTHON,充實這裡的版面^_^ kayjean Member Posts: 2 ‧ Re: 請問兩個問題:cgi程式和Unicode問題 Posted by yungyuc at 2005-11-03 06:51 * Quote * Reply * * 如果原本就考慮寫 apache module,或許可以參考一下 mod_python。 可以避開 CGI 的 fork tax,大幅增加效率。 yungyuc Member Posts: 1 ‧ Re: 請問兩個問題:cgi程式和Unicode問題 Posted by cphsu at 2005-11-04 08:17 * Quote * Reply * * 若不嫌棄, 小弟之前有分享一些 Python CGI 的相關經驗於以下網址: http://www.python.org.tw/Members/cphsu/tutorials/PythonCGI.htm 但如同 yungyuc 所提到的, 用 mod_python 效能上會比較好一點 ^_^, Best Regards, Kent Hsu cphsu Member Posts: 10 ‧ Re: 請問兩個問題:cgi程式和Unicode問題 Posted by cphsu at 2005-11-04 08:28 * Quote * Reply * * 在 http://wiki.python.org/moin/WebProgramming 也有許多寫 Web 應用程式的 framework, 可以參考看. cphsu Member Posts: 10 ‧ Re: 請問兩個問題:cgi程式和Unicode問題 Posted by kayjean at 2005-11-06 22:25 * Quote * Reply * * 1.感謝各位的協助,目前使用一般的Apache+CGI就可以了 2.剛剛花了一些時間看python的web framework,感覺都很不錯,下次有需要的話可以拿一個來試試看.我看的是 a.http://www.turbogears.org/ 蠻完整的 b.http://www.myghty.org/ 似乎想比照jsp的方式運作 3.我平常熟悉的framework是.net,雖然我很不喜歡M$,可是不得不說.net真的是簡單方便到不得了的程度,另外最近在研究 Java Spring framework就困難多了.相形之下Python的framework似乎規模都比較小,不過這樣要嘗試才會知道. http://www.python.org.tw/Members/cphsu/tutorials/PythonCGI.htm 如果只是要讀一個 .zip 檔的內容,可以這樣寫: import zipfile zip = zipfile.ZipFile('input.zip') # zip 是代表 .zip 檔的物件 filename_list = zip.namelist() # zip 檔中的檔案名稱清單 content = zip.read(filename_list[0]) # 把 .zip 中的第一個檔案讀出來 zip.close() gzip 是用在以 gzip 壓縮的檔案,用 gzip.GzipFile('檔名') 打開後,可以用一般檔案的介面 (read, readline, readlines, write, close) 操作。 # 把內容直接寫進壓縮檔 gzout = gzip.GzipFile('file.gz', 'w') gzout.write('''A test file 第二行 ''') gzout.close() # 印出檔案內容 for line in gzip.GzipFile('file.gz'): print line, 不過我沒用過 tarfile。 pyeh Anonymous Posts: n/a ‧ Re: 請問zipfile怎麼用? Posted by cphsu at 2005-08-23 21:48 * Quote * Reply * * tarfile的用法剛好在手冊中有範例, 我摘錄其中一個上來, 其它的可以看手冊 How to create an uncompressed tar archive from a list of filenames: import tarfile tar = tarfile.open("sample.tar", "w") for name in["foo", "bar", "quux"]: tar.add(name) tar.close()Gnuplot Usage@python
fac(n) = (n==0) ? 1 : n * fac(n-1) fac(x) = (int(x)==0) ? 1.0 : int(x) * fac(int(x)-1.0) stirling(x) = sqrt(2*pi*x) * x**x * exp(-x) set xrange [1:15] set yrange [1:1e+10] set log y set sample 15 plot stirling(x) notitle with lines, fact(x) notitle with points #fact(n) ~ sqrt(2pi*x)x^x*exp(-x)
http://t16web.lanl.gov/Kawano/gnuplot/index-e.html
http://members.aol.com/demalion2/index.html http://www.blender3d.org/cms/Home.2.0.html
http://www.geom.uiuc.edu/~banchoff/projects.html torus
http://mathworld.wolfram.com/Torus.html
http://www.mmit.stc.sh.cn/telecenter/CnHisScience/yuanzhou.htm
http://www.mathland.idv.tw/ 昌爸工作坊
http://zh.wikipedia.org/wiki/%E5%9C%93%E5%91%A8%E7%8E%87 割圓術、圓周率
gnuplot是用來繪圖專用的軟體,它符合組合學習的方式,所以就來練習一下。
參考連結:
如果用攝氏和華氏的溫度轉換來學習,應該是很好的應用範例。
F=C*1.8+32,可以列出下列的數據對:
-49 -56.20 -42 -43.60 -35 -31.00 -28 -18.40 -21 -5.80 -14 6.80 -7 19.40 0 32.00 7 44.60 14 57.20 21 69.80 28 82.40 35 95.00 42 107.60
然後透過python令gnuplot來畫圖。
同樣的方式,也可以來畫2次函式圖,如繪出3x^2+9x-83的函式圖,比較可以直覺地教授2次函 式的特性如:頂點、向上vs向下、與x軸的交點、面積...>等等。
Xml Usage@Python
xml@python
RDFResource Description Framework (RDF)
Primer: Getting into RDF & Semantic Web using N3
xmltex
http://www.dcarlisle.demon.co.uk/xmltex/manual.html http://www.mathmlconference.org/2000/Talks/carlisle/ http://a2.pluto.it/a2371.htm XMLTeX e PassiveTeXvideo python
import win32com.client
strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("Select * from CIM_VideoControllerResolution")
for objItem in colItems:
print "Caption: ", objItem.Caption
print "Description: ", objItem.Description
print "Horizontal Resolution: ", objItem.HorizontalResolution
print "Max Refresh Rate: ", objItem.MaxRefreshRate
print "Min Refresh Rate: ", objItem.MinRefreshRate
print "Number Of Colors: ", objItem.NumberOfColors
print "Refresh Rate: ", objItem.RefreshRate
print "Scan Mode: ", objItem.ScanMode
print "Setting ID: ", objItem.SettingID
print "Vertical Resolution: ", objItem.VerticalResolution
import win32com.client
strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("Select * from Win32_DisplayConfiguration")
for objItem in colItems:
print "Bits Per Pel: ", objItem.BitsPerPel
print "Caption: ", objItem.Caption
print "Description: ", objItem.Description
print "Device Name: ", objItem.DeviceName
print "Display Flags: ", objItem.DisplayFlags
print "Display Frequency: ", objItem.DisplayFrequency
print "Dither Type: ", objItem.DitherType
print "Driver Version: ", objItem.DriverVersion
print "ICM Intent: ", objItem.ICMIntent
print "ICM Method: ", objItem.ICMMethod
print "Log Pixels: ", objItem.LogPixels
print "Pels Height: ", objItem.PelsHeight
print "Pels Width: ", objItem.PelsWidth
print "Setting ID: ", objItem.SettingID
print "Specification Version: ", objItem.SpecificationVersion
import win32com.client
strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("Select * from Win32_DesktopMonitor")
for objItem in colItems:
print "Availability: ", objItem.Availability
print "Bandwidth: ", objItem.Bandwidth
print "Caption: ", objItem.Caption
print "Config Manager Error Code: ", objItem.ConfigManagerErrorCode
print "Config Manager User Config: ", objItem.ConfigManagerUserConfig
print "Creation Class Name: ", objItem.CreationClassName
print "Description: ", objItem.Description
print "Device ID: ", objItem.DeviceID
print "Display Type: ", objItem.DisplayType
print "Error Cleared: ", objItem.ErrorCleared
print "Error Description: ", objItem.ErrorDescription
print "Install Date: ", objItem.InstallDate
print "Is Locked: ", objItem.IsLocked
print "Last Error Code: ", objItem.LastErrorCode
print "Monitor Manufacturer: ", objItem.MonitorManufacturer
print "Monitor Type: ", objItem.MonitorType
print "Name: ", objItem.Name
print "Pixels Per X Logical Inch: ", objItem.PixelsPerXLogicalInch
print "Pixels Per Y Logical Inch: ", objItem.PixelsPerYLogicalInch
print "PNP Device ID: ", objItem.PNPDeviceID
z = objItem.PowerManagementCapabilities
if z is None:
a = 1
else:
for x in z:
print "Power Management Capabilities: ", x
print "Power Management Supported: ", objItem.PowerManagementSupported
print "Screen Height: ", objItem.ScreenHeight
print "Screen Width: ", objItem.ScreenWidth
print "Status: ", objItem.Status
print "Status Info: ", objItem.StatusInfo
print "System Creation Class Name: ", objItem.SystemCreationClassName
print "System Name: ", objItem.SystemName
import win32com.client
strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("Select * from Win32_DisplayControllerConfiguration")
for objItem in colItems:
print "Bits Per Pixel: ", objItem.BitsPerPixel
print "Caption: ", objItem.Caption
print "Color Planes: ", objItem.ColorPlanes
print "Description: ", objItem.Description
print "Device Entries In A Color Table: ", objItem.DeviceEntriesInAColorTable
print "Device Specific Pens: ", objItem.DeviceSpecificPens
print "Horizontal Resolution: ", objItem.HorizontalResolution
print "Name: ", objItem.Name
print "Refresh Rate: ", objItem.RefreshRate
print "Reserved System Palette Entries: ", objItem.ReservedSystemPaletteEntries
print "Setting ID: ", objItem.SettingID
print "System Palette Entries: ", objItem.SystemPaletteEntries
print "Vertical Resolution: ", objItem.VerticalResolution
print "Video Mode: ", objItem.VideoMode
import win32com.client
strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("Select * from Win32_VideoController")
for objItem in colItems:
z = objItem.AcceleratorCapabilities
if z is None:
a = 1
else:
for x in z:
print "Accelerator Capabilities: ", x
print "Adapter Compatibility: ", objItem.AdapterCompatibility
print "Adapter DAC Type: ", objItem.AdapterDACType
print "Adapter RAM: ", objItem.AdapterRAM
print "Availability: ", objItem.Availability
z = objItem.CapabilityDescriptions
if z is None:
a = 1
else:
for x in z:
print "Capability Descriptions: ", x
print "Caption: ", objItem.Caption
print "Color Table Entries: ", objItem.ColorTableEntries
print "Config Manager Error Code: ", objItem.ConfigManagerErrorCode
print "Config Manager User Config: ", objItem.ConfigManagerUserConfig
print "Creation Class Name: ", objItem.CreationClassName
print "Current Bits Per Pixel: ", objItem.CurrentBitsPerPixel
print "Current Horizontal Resolution: ", objItem.CurrentHorizontalResolution
print "Current Number Of Colors: ", objItem.CurrentNumberOfColors
print "Current Number Of Columns: ", objItem.CurrentNumberOfColumns
print "Current Number Of Rows: ", objItem.CurrentNumberOfRows
print "Current Refresh Rate: ", objItem.CurrentRefreshRate
print "Current Scan Mode: ", objItem.CurrentScanMode
print "Current Vertical Resolution: ", objItem.CurrentVerticalResolution
print "Description: ", objItem.Description
print "Device ID: ", objItem.DeviceID
print "Device Specific Pens: ", objItem.DeviceSpecificPens
print "Dither Type: ", objItem.DitherType
print "Driver Date: ", objItem.DriverDate
print "Driver Version: ", objItem.DriverVersion
print "Error Cleared: ", objItem.ErrorCleared
print "Error Description: ", objItem.ErrorDescription
print "ICM Intent: ", objItem.ICMIntent
print "ICM Method: ", objItem.ICMMethod
print "Inf Filename: ", objItem.InfFilename
print "Inf Section: ", objItem.InfSection
print "Install Date: ", objItem.InstallDate
print "Installed Display Drivers: ", objItem.InstalledDisplayDrivers
print "Last Error Code: ", objItem.LastErrorCode
print "Max Memory Supported: ", objItem.MaxMemorySupported
print "Max Number Controlled: ", objItem.MaxNumberControlled
print "Max Refresh Rate: ", objItem.MaxRefreshRate
print "Min Refresh Rate: ", objItem.MinRefreshRate
print "Monochrome: ", objItem.Monochrome
print "Name: ", objItem.Name
print "Number Of Color Planes: ", objItem.NumberOfColorPlanes
print "Number Of Video Pages: ", objItem.NumberOfVideoPages
print "PNP Device ID: ", objItem.PNPDeviceID
z = objItem.PowerManagementCapabilities
if z is None:
a = 1
else:
for x in z:
print "Power Management Capabilities: ", x
print "Power Management Supported: ", objItem.PowerManagementSupported
print "Protocol Supported: ", objItem.ProtocolSupported
print "Reserved System Palette Entries: ", objItem.ReservedSystemPaletteEntries
print "Specification Version: ", objItem.SpecificationVersion
print "Status: ", objItem.Status
print "Status Info: ", objItem.StatusInfo
print "System Creation Class Name: ", objItem.SystemCreationClassName
print "System Name: ", objItem.SystemName
print "System Palette Entries: ", objItem.SystemPaletteEntries
print "Time Of Last Reset: ", objItem.TimeOfLastReset
print "Video Architecture: ", objItem.VideoArchitecture
print "Video Memory Type: ", objItem.VideoMemoryType
print "Video Mode: ", objItem.VideoMode
print "Video Mode Description: ", objItem.VideoModeDescription
print "Video Processor: ", objItem.VideoProcessorMisc Usage@Python
Python & Webservices
使用Python來寫Webservices是非常有趣且容易的事,pymedia
http://mail.python.org/pipermail/python-announce-list/2004-June/003160.html http://pymedia.org/ http://pymedia.org/tut/index.html cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/pymedia login cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/pymedia co -P pymedia
PyMedia library is a Python module for wav, mp3, ogg, avi, divx, dvd, cdda etc files manipulations. It allows you to parse, demutiplex, multiplex, decode and encode all supported formats. Also it features direct interface to a DVD-ROM drive allowing you to extract Audio disks, DVD and VCD movies. Sound interface is making it a snap to play sound on a selected audio card. Resample and reformat your sound before you play it. Features page can help you to see what else you can do with PyMedia.
PyMedia is very small in size and very flexible at the same time. See tutorial for numerous list of examples. It allows you to create your own mutimedia applications in a matter of minutes by even a newbie in programming. Python language is choosen because of simple semantics, complete and reach set of features.
There is a PyCar application which takes advantage of the PyMedia library extensivelly and serve in my car as a powerful car media center.
secure directory
Security DirGPS written in Python
http://pygps.org/ http://conversationswithmyself.com/maps/tracker/gmapTracker.htmlTkinter Usage
一般處理圖形都是透過Image,但也是可用Tkinter將圖形顯示出來。 Miller -- 物理/Python同好Visual Python
VPython Link
Python@Physics&Science -- Py@Psi
一直想要將物理與Programming Technique連結,但是無法順利地將夢想實現,總算在cyberworld中,有這樣想法的人還是存在的,我想將這部份要發展的software,在sourceforge上開發專案的Codename叫作Py@Psi。
Py@Psi名稱即取自python的諧音,同時也是取自數學的重要常數pi的發音,另外Physics&Science的諧音為Psi,Psi是在量子物理中很重要的函數代號,此2者合起來叫作Py@Psi,表示在Sourceforge上開發的專案,是專注在將物理與科學上的現象,呈現出圖象化,現階段先來介紹vpython。
Visual Python
為了要2D/3D的繪圖加速,vpython使用boost來將python的程式,用C++包裝起來(Wrapping),且使用POV-RAY的繪圖、OpenGL的繪圖方式,來將物理定律呈現。
CVS snapshot
cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/visualpython login (just Enter) cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/visualpython co vpython
但是在安裝CVS snapshot,無法找到configure,因為那是要自己作出來的,所以就安裝下列的套件,試試看可否安裝成功。
autotools-dev libtool autoconf automake1.4 m4
最快的方式,就是安裝python-visual,同時也會安裝了下列的套件
gtkglarea5 libboost-python1.33.0 python-visual