Get the server IP of BaseHTTPServer.BaseHTTPRequestHandler

获取 BaseHTTPServer.BaseHTTPRequestHandler 请求服务器的 IP。

serveradress = re.findall('Host: (.*?)\r\n',str(self.headers))

Show PIL image object in browser

在浏览器显示 PIL 处理过的图片对象。

Using PIL module, you can resize or crop an image and return an image object. After that, I want to show the resized-image-object in browser. Here it is.

pic = thumbPicture()
f = StringIO(),'JPEG')
self.sendHeader(contenttype = 'image/jpeg',contentlength = f.tell())

Get parameters from BaseHTTPServer http GET request

BaseHTTPHandler from the BaseHTTPServer module doesn’t seem to provide any convenient way to access http request parameters. What is the best way to parse the GET parameters from the path, and the POST parameters from the request body?

Right now, I’m using this for GET:

parsed_path = urlparse.urlparse(self.path)
    params = dict([p.split('=') for p in parsed_path[4].split('&')])
    params = {}




细节上,Python 如此简洁优美的语法让我写的是惨不忍睹,Python 自带的模块、函数还很不熟悉。



准确说应该是昨天,6 月 26 日离开学校整一年。



cdto open iTerm

cdto:Fast mini application that opens a window cd’d to the front most finder window,快速在当前路径打开一个 Termainal。iTerm 是 Mac 下一个增强终端。默认状态下 cdto 是打开系统自带的,其实 cdto 也是支持 iTerm 的。

右键 Show Package Contents 打开,将 Contents/Plugins Disabled 下的 iterm.bundle mv 替换 Contents/Plugins 下 terminal.bundle 即可。

Mac OS X: decoder jpeg not available

When you are using PIL to resize a JPEG image file, you will probably have a “decoder jpeg not available” error,this means that PIL doesn’t have JPEG support.

Here is the solution:

  1. Download and install MacPorts.
  2. sudo port install jpeg, this will install libjpeg.
  3. sudo port install py25-pil

That’s it.

Simple HTTP Server in Python

Python has an embedded HTTP server that can serve the current directory from a given port.

python -m SimpleHTTPServer 8000

You and me


2010 FIFA World Cup South Africa

2010 FIFA World Cup Aouth Africa