2011年11月9日 星期三

Python3 應用

  1. Java有Quartz這個強大的排程套件,Python當然也有=>Advanced Python Scheduler (APScheduler)
  2. 簡單的http client (Python3以前是httplib)
'''
Created on 2011/11/10
這個程式可以簡單的測試網頁伺服器是否運作正常 
@author: Joseph
'''

import http.client

conn = http.client.HTTPConnection("www.google.com.tw")  
conn.request('GET', '/')  
r1 = conn.getresponse() 
print(r1.status, r1.reason) #正常的話會印出 200 OK
conn.close()

3. 加密 hash
'''
Created on 2011/11/10

@author: Joseph
'''
import hashlib
md5 = hashlib.md5()
#官網 Note : Feeding string objects is to update() is not supported, as hashes work on bytes, not on characters.
md5.update(b"This is a book")#因為上述,所以字串前多加一個b
print(md5.digest())  #加密後用二進位表示  
print(md5.hexdigest()) #加密後用十六進位表示  
#第7,9,11合在一起成下列寫法
print(hashlib.new("md5", b"This is a book").hexdigest()) 

沒有留言:

張貼留言

AI 時代的影響(2026-10-24的心得)

  寫了半個世紀程式、 曾出版《Clean Code》教全世界工程師把程式碼寫乾淨的 Robert C. Martin(Uncle Bob), 最近公開表示他已經有超過 95% 的時間不再逐行閱讀 AI 寫的程式碼。 一位一生都在強調「程式碼是寫給人讀的」宗師級人物,何以敢做出...