本文執行個體講述了python通過get,post方式發送http請求和接收http響應的方法。分享給大家供大家參考。具體如下:測試用CGI,名字為test.py,放在apache的cgi-bin目錄下:#!/usr/bin/pythonimport cgidef main(): print "Content-type: text/html\n" form = cgi.FieldStorage() if form.has_key("ServiceCode") and
本文執行個體講述了python zip和unzip資料的方法。分享給大家供大家參考。具體實現方法如下:# zipping and unzipping a string using the zlib module# a very large string could be zipped and saved to a file speeding up file writing time # and later reloaded and unzipped by another program
本文執行個體講述了Python功能鍵的讀取方法。分享給大家供大家參考。具體分析如下:先getch一下得到a,如果等於0或者224,就說明是功能鍵,再getch下一個得到b,那麼這個功能鍵的掃描碼就是a+(b*256) 。可以看看下面這個例子:import msvcrt while 1: if msvcrt.kbhit(): # Key pressed a = ord(msvcrt.getch()) # get first byte of keyscan code
本文執行個體講述了python刪除到期檔案的方法。分享給大家供大家參考。具體實現方法如下:# remove all jpeg image files of an expired modification date = mtime# you could also use creation date (ctime) or last access date (atime)# os.stat(filename) returns (mode, ino, dev, nlink, uid, gid,
本文執行個體講述了python集合用法。分享給大家供大家參考。具體分析如下:# sets are unordered collections of unique hashable elements# Python23 tested vegaseat 09mar2005# Python v2.4 has sets built inimport setsprint "List the functions within module 'sets':"for funk in dir(sets):
本文執行個體講述了Python smallseg分詞用法。分享給大家供大家參考。具體分析如下:#encoding=utf-8 #import psyco #psyco.full() words = [x.rstrip() for x in open("main.dic",mode='r',encoding='utf-8') ] from smallseg import SEG seg = SEG() print('Load dict...') seg.set(words)
本文執行個體講述了基於wxpython實現的windows GUI程式。分享給大家供大家參考。具體如下:# using a wx.Frame, wx.MenuBar, wx.Menu, wx.Panel, wx.StaticText, wx.Button, # and a wx.BoxSizer to show a rudimentary wxPython Windows GUI application# wxPython package from:
本文執行個體講述了python影像處理之鏡像實現方法。分享給大家供大家參考。具體分析如下:映像的鏡像變化不改變映像的形狀。映像的鏡像變換分為三種:水平鏡像、垂直鏡像、對角鏡像設映像的大小為M×N,則水平鏡像可按公式I = iJ = N - j + 1垂直鏡像可按公式I = M - i + 1J = j對角鏡像可按公式I = M - i + 1J = N - j + 1值得注意的是在OpenCV中座標是從[0,0]開始的所以,式中的 +1 在編程時需要改為