Time of Update: 2016-06-06
Python基本內建資料類型有哪些一些基礎資料型別 (Elementary Data
Time of Update: 2016-06-06
編寫tasks.py 代碼如下:from celery import Celeryfrom tornado.httpclient import HTTPClientapp = Celery('tasks')app.config_from_object('celeryconfig')@app.taskdef get_html(url): http_client = HTTPClient() try: response =
Time of Update: 2016-06-06
Beautiful Photo!: http://www.beautifulphoto.net/ 代碼如下:import urllib2import re_random_url = r'http://www.beautifulphoto.net/plugin/RndArticle/'_img_patt = re.compile(r'')def random(timeout=3, more=False): try: html = urllib2.urlopen(_random_
Time of Update: 2016-06-06
代碼如下:import urllib.requestimport reimport timedef movie(movieTag): tagUrl=urllib.request.urlopen(url) tagUrl_read = tagUrl.read().decode('utf-8') return tagUrl_readdef subject(tagUrl_read): ''' 這裡還存在問題:
Time of Update: 2016-06-06
代碼如下:# -*- coding: utf-8 -*-import sysfrom PyQt4 import QtCore, QtGuiclass MyWindow(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self,parent ) self.setWindowTitle("weather") self.resize(1000, 200)
Time of Update: 2016-06-06
環境Python 2.7.6,BS4,在powershell或命令列均可運行。請確保安裝了BS模組 代碼如下:# -*- coding:utf8 -*-# 2013.12.36 19:41 wnlo-c209# 抓取dbmei.com的圖片。from bs4 import BeautifulSoupimport os, sys, urllib2# 建立檔案夾,昨天剛學會path = os.getcwd() # 擷取此指令碼所在目錄new_path = os.path.join(
Time of Update: 2016-06-06
大家都知道,linux裡一切皆為檔案,在linux/unix的根目錄下,有個/proc目錄,這個/proc 是一種核心和核心模組用來向進程(process)發送資訊的機制(所以叫做“/proc”),這個偽檔案系統允許與核心內部資料結構互動,擷取有關進程的有用資訊,在運行中(on the fly)改變設定(通過改變核心參數)。與其他檔案系統不同,/proc 存在於記憶體而不是硬碟中。proc 檔案系統提供的資訊如下:•進程資訊:系統中的任何一個進程,在 proc
Time of Update: 2016-06-06
利用這個小遊戲可以學習一下ython3.3中tkinter的使用方法 代碼如下:# -*- coding: utf-8 -*-import tkinter as tkimport sysimport randomimport renumber = random.randint(0,1024)running = Truenum = 0nmaxn = 1024nminn = 0def eBtnClose(event): root.destroy()def eBtnGuess(event):
Time of Update: 2016-06-06
linux系統使用python擷取cpu資訊指令碼分享 代碼如下:#!/usr/bin/env Pythonfrom __future__ import print_functionfrom collections import OrderedDictimport pprintdef CPUinfo(): ''' Return the information in /proc/CPUinfo as a dictionary in the following format:
Time of Update: 2016-06-06
1 將下面代碼拷貝到一個檔案,命名為asyncore.py 代碼如下:import socketimport selectimport sysdef ds_asyncore(addr,callback,timeout=5): s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.connect(addr) r,w,e = select.select([s],[],[],timeout) if r:
Time of Update: 2016-06-06
昨天翻硬碟,找到一個好東西,可惜自己加了密碼自己不記得了。試了幾個常用的沒試出來,於是寫了這麼個小指令碼來替我嘗試。。呵呵,還真給解出來了。python指令碼內容如下,跑跑自己加密的壓縮包還不錯 代碼如下:# -*- coding: utf-8 -*-import sys,osdef IsElementUniq(list): """ 判斷list中的元素是否為唯一的 """ for word in list: if
Time of Update: 2016-06-06
代碼如下:# encoding:utf-8### 檔案名稱如:# 下吧.mp3##import os,refs=os.listdir('xb')for f in fs: ######方法一:partition擷取無用字元 #1.將檔案名稱以'['符分為3部分 #ls=f.partition('[') #2.ls[0]為需要檔案名稱,因此擷取ls[1:] #dirtystring = ''.join(ls[1:]) #3.開始替換 #newname=f.replace(dirtystring, '
Time of Update: 2016-06-06
方法一: 代碼如下:f = open("foo.txt") # 返回一個檔案對象 line = f.readline() # 調用檔案的 readline()方法 while line: print line, # 後面跟 ',' 將忽略分行符號 # print(line, end = '') # 在 Python 3中使用 line = f.readline()
Time of Update: 2016-06-06
模版基本介紹模板是一個文本,用於分離文檔的表現形式和內容。 模板定義了預留位置以及各種用於規範文檔該如何顯示的各部分基本邏輯(模板標籤)。 模板通常用於產生HTML,但是Django的模板也能產生任何基於文字格式設定的文檔。來一個項目說明1、建立MyDjangoSite項目具體不多說,參考前面。2、在MyDjangoSite(包含四個檔案的)檔案夾目錄下建立templates檔案夾存放模版。3、在剛建立的模版下建模版檔案user_info.html 代碼如下: 使用者資訊
Time of Update: 2016-06-06
代碼如下:# -*- coding: UTF-8 -*-import mysql.connector as dbimport client.tWeiboimport timeif __name__ == '__main__': connect = db.connect(user='root',db='collection',password='',host="127.0.0.1") cursor = connect.cursor() cursor.execute("SET SQL_MODE =
Time of Update: 2016-06-06
Python 2.6中print不是函數,而是一個關鍵字,使用方式如下: 代碼如下:print 1, 2 print 'a', 'b' 顯示結果如下,用逗號分隔的各項之間會列印出一個空格,預設以換行結束: 代碼如下:1 2 a b若不想以換行結束,則在最後加一個“,”,如下所示: 代碼如下:print 1, 2, print 'a', 'b'顯示結果如下: 代碼如下:1 2 a b Python 3.0中print變成了一個內建函數
Time of Update: 2016-06-06
仔細觀察下面兩個python程式,代碼一模一樣,但是啟動並執行結果卻不同,就是因為最後一行return縮排的不同 代碼如下:def powersum(power, *args):'''Return the sum of each argument raised to specified power.'''total = 0for i in args:total += pow(i, power)return total運行時輸入powersum(2,3,4)輸出25(3的平方加上4的平方)
Time of Update: 2016-06-06
代碼如下:#設a為字串import timea = "2011-09-28 10:00:00"#中間過程,一般都需要將字串轉化為時間數組time.strptime(a,'%Y-%m-%d %H:%M:%S')>>time.struct_time(tm_year=2011, tm_mon=9, tm_mday=27, tm_hour=10, tm_min=50, tm_sec=0, tm_wday=1, tm_yday=270, tm_isdst=-1)#將"2011-09-28 10:00:00
Time of Update: 2016-06-06
代碼如下:#coding=utf8__author__ = 'Administrator'# 當函數的參數不確定時,可以使用*args和**kwargs。*args沒有key值,**kwargs有key值def fun_var_args(farg, *args): print 'args:', farg for value in args: print 'another arg:',value# *args可以當作可容納多個變數組成的list或tuplefun_var_
Time of Update: 2016-06-06
1. iterator疊代器最簡單例子應該是數組下標了,且看下面的c++代碼: 代碼如下:int array[10];for ( int i = 0; i printf("%d ", array[i]);疊代器工作在一個容器裡(array[10]),它按一定順序(i++)從容器裡取出值(array[i])並進行操作(printf("%d ", array[i])。上面的代碼翻譯成python: 代碼如下: array = [i for i in range(10)]for i in