本文執行個體講述了python中enumerate函數用法。分享給大家供大家參考。具體分析如下:今日發現一個新函數 enumerate 。一般情況下對一個列表或數組既要遍曆索引又要遍曆元素時,會這樣寫:for i in range (0,len(list)): print i ,list[i]但是這種方法有些累贅,使用內建enumerrate函數會有更加直接,優美的做法,先看看enumerate的定義:def enumerate(collection): 'Generates an
本文執行個體講述了Python使用shelve模組實現簡單資料存放區的方法。分享給大家供大家參考。具體分析如下:Python的shelve模組提供了一種簡單的資料存放區方案,以dict(字典)的形式來操作資料。#!/usr/bin/pythonimport sys, shelvedef store_person(db): """ Query user for data and store it in the shelf object """ pid = raw_input('Enter
本文執行個體講述了wxPython中listbox用法。分享給大家供大家參考。具體如下:# load a listbox with names, select a name and display in title# experiments with wxPython by vegaseat 20mar2005# Python v2.4 and wxPython v2.5# If you have not already done so, install Python 2.4 first.#
本章將覆蓋所有在Python中使用的基本I/O功能。有關更多函數,請參考標準Python文檔。列印到螢幕上:產生輸出最簡單的方法是使用print語句,可以通過用逗號分隔的零個或多個運算式。該函數將傳遞到一個字串運算式,並將結果寫到標準輸出,如下所示:#!/usr/bin/pythonprint "Python is really a great language,", "isn't it?";這將產生結果輸出在標準螢幕上,結果如下:Python is really a great
本文執行個體講述了django通過ajax發起請求返回JSON格式資料的方法。分享給大家供大家參考。具體實現方法如下:這是幕後處理的:def checkemail(request): user = None if request.POST.has_key('email'): useremail = request.POST['email'] result = {} user = User.objects.filter(useremail__iexact =
本文執行個體講述了python簡單實現旋轉圖片的方法。分享給大家供大家參考。具體實現方法如下:# rotate an image counter-clockwise using the PIL image library# free from: http://www.pythonware.com/products/pil/index.htm# make sure to install PIL after your regular python package is