Time of Update: 2018-12-05
Python之Windows控制項操作系列一:類比滑鼠點擊http://www.cnblogs.com/sanquanfeng/archive/2012/01/13/2321519.html類比滑鼠點擊指定視窗中的指定button:import win32gui,win32apiwin = win32gui.FindWindow(None,DialogName)while win == 0: win =
Time of Update: 2018-12-05
控制流程語句:1.if語句lines = 1543 if lines < 1000: print("small") elif lines < 10000: print("medium") else: print("large") #medium #Python裡面用縮排代替了{}、begin..end之類的,看起來有點怪啊,不過習慣起來還好。每一個條件陳述式後面都要跟:,另外elseif被簡化成了elif 2.while語句while
Time of Update: 2018-12-05
異常處理try: try_suite except exception1 as variable1: exception_suite1 ... except exceptionN as variableN: exception_suiteN s = input("enter an integer:") try: i = int(s) print("valid integer entered:", i) except
Time of Update: 2018-12-05
class BST: def __init__(self): self.root = None def insert(self,x): if self.root == None: self.root = Node(x) elif self.root.data > x: self.root.left = self.root.left.insert(x) elif
Time of Update: 2018-12-05
㈠ Python 依賴包# rpm -q gcc gdbm-devel readline-devel ncurses-devel zlib-devel bzip2-develsqlite-devel db4-devel openssl-devel tk-devel bluez-libs-devel make --qf '%{name}.%{arch}\n'|sort ㈡ 安裝 Python 2.7 # wget
Time of Update: 2018-12-05
# coding=UTF-8import ConfigParserclass MyClass(object): ''' 取設定檔 ''' def __init__(self): self.path = "../config/config.ini" try : self.cf = ConfigParser.ConfigParser() self.cf.read(self.path)
Time of Update: 2018-12-05
#! /usr/bin/env pythonclass BTNode: def __init__(self, data, left, right): self.data = data self.left = left self.right = rightclass BTree: def __init__(self, root): self.root = root; def insert(self,
Time of Update: 2018-12-05
import osimport os.pathimport shutilimport time, datetimedef copyFiles(sourceDir, targetDir): if sourceDir.find(".svn") > 0: return for file in os.listdir(sourceDir): sourceFile = os.path.join(sourceDir, file) print
Time of Update: 2018-12-05
Monkeyrunner 寫指令碼的技巧(shell 命令,檔案操作)Android 4.0已經發布了,令我失望的一點是monkeyrunner工具本身沒有大的提高,SDK看上去沒有什麼變化,但是之前曾將看到趨勢,源碼已經引入Ichampview和ease等新的模組,可惜源碼還沒有發布,不知道具體情況,況且現在的monkeyrunner也無法執行。感覺目前sdk列出的功能太少,在寫指令碼的時候,限制太多,好在monkeyrunner的指令碼是python形式的,豐富的庫檔案可以彌補這一缺陷1.
Time of Update: 2018-12-05
Python編程擷取當前路徑在編寫各類應用程式時,擷取當前路徑一直是一個經典問題,只有擷取了當前路徑才可以進一步找到所有同路徑下的其它檔案。Python程式設計語言也可以通過一些系統調用來獲得當前路徑。本文給出的模組不僅僅可以擷取當前路徑,也可以形成SQLObject使用的URI形式字串,以當前路徑下的指定檔案名稱合成資料庫路徑。如下是代碼,大家可以研究一下:# -*- coding: gbk -*-# File: curpath.py# Date: 2006-12-23# Authro:
Time of Update: 2018-12-05
In Python, string objects are immutable. Therefore, any operation on a string, including string concatenation, produces a new string object, rather than modifying an existing one. concatenating N strings thus involves building and then immediately
Time of Update: 2018-12-05
import datetime if __name__ == "__main__": t1=datetime.datetime.today() f = file("email.txt","r") f2 = file("email_new.txt","w") f2.writelines(set(f)) f.close() f2.close() t2=datetime.datetime.today() print str(t2-t1) 在我機器上的測試結果: python 2.5: 0:00:00
Time of Update: 2018-12-05
python實現類比滑鼠代碼作者: 笑嘻嘻 日期: 2010-11-13 15:34字型大小: 小 中 大沒有任何經驗,網上找的代碼自己在拼湊。python預設是沒有安裝pywin32的,需要下載。http://sourceforge.net/projects/pywin32/ 說一下環境吧,某棋牌遊戲大廳的五子棋。想實現滑鼠類比點擊開始按鈕。最終是想類比實現下棋,也就是外掛啦。一步步來吧。誰讓技術不行呢,只能摸索了。 中間遇到的問題: 1、win32gui.FindWindow('HGE_
Time of Update: 2018-12-05
python實現網站的自動登入 2012-01-10 17:15:58| 分類:編程 |字型大小 訂閱 前段時間幫同學寫了個程式,其中需要在後台通過訪問url來發送郵件,經過摸索,用了php的curl功能,覺得很強大,於是google了下。python作為一款強大的指令碼語言,也同樣有類似的功能,於是嘗試著做了下。 先看下這簡短的幾行代碼import urllib,urllib2,httplib,cookielib //使用的python模組url = '
Time of Update: 2018-12-05
LIST(列表)是序列對象,可包含任意的Python資料資訊,如字串、數字、列表、元組等。列表的資料是可變的,我們可通過對象方法對列表中的資料進行增加、修改、刪除等操作。可以通過list(seq)函數把一個序列類型轉換成一個列表。下面舉幾個例子:list1 = ["a", "b", "c"] #字元列表list2 = [1, 2, 3, 4, 5, 6] #數字列表list3 = [1, 2, "One", "Two"] #混合列表list4 = [[1, 2, 3], ["a, "b",
Time of Update: 2018-12-05
內建模組(不用import就可以直接使用)常用內建函數: Python代碼 help(obj) 線上協助, obj可是任何類型 callable(obj) 查看一個obj是不是可以像函數一樣調用 repr(obj) 得到obj的表示字串,可以利用這個字串eval重建該對象的一個拷貝 eval_r(str) 表示合法的python運算式,返回這個運算式 dir(obj) 查看obj的name space中可見的name
Time of Update: 2018-12-05
今天想起之前在argo看到的求1111!裡有多少個1的題目, 有人回帖說用python求得結果是255, 於是搜了一下怎麼做.最簡單的當然是寫遞迴了, 不過最簡便的則是用reduce函數 >>> from functools import reduce>>> str(reduce(lambda x,y: x*y, range(1, 1112))).count('1')255>>> 順便喊歎一下python真厲害, 可以算到這麼大的數
Time of Update: 2018-12-05
用兩個底線開頭的函數是私人函數. 雖然說是私人的, 但是還是可以在類外引用>>> class test:def __private():print("private");>>> a = test()>>> a.__private()Traceback (most recent call last): File "<pyshell#5>", line 1, in <module>
Time of Update: 2018-12-05
類變數緊接在類名後面定義,相當於java和c++的static變數執行個體變數在__init__裡定義,相當於java和c++的普通變數 >>> class test:count = 0;def __init__(self, c):self.count = c;self.__class__.count = self.__class__.count + 1;>>> a = test(3)>>> a.count3>>>
Time of Update: 2018-12-05
我花了一下午的時間完成了一個簡單語言的解譯器,我會在最後帖出所有代碼,但是今天不打算詳細解釋程式的每一個步驟,最近考慮找實習、做論文,要花一些時間。有時間了我會解釋每一部分,在這裡只提醒一下讀者,程式的寫作過程和它呈現出來的不一樣,總體來說我的寫作過程是先寫一個只包含一條指令的解譯器,然後逐漸加入其他指令。ps:我是多麼的想看看高手們寫程式的過程,而不只是結果,但是就像graham說的“寫的過程往往顯得冗長”,所以這方面的書籍不多。我覺得比較接近的書包括《clean code》、《paip》、《