完成了Eclipse和PyDev的安裝
我們就可以用很方便的IDE工具來編寫我們所需的軟體
接下來我們就回到Dive Into Python 中文版的電子書來看看第一個範例
http://www.woodpecker.org.cn/diveintopython/getting_to_know_python/index.html
首先將範例檔下載到我們的電腦中
檔案在這裡http://www.woodpecker.org.cn/diveintopython/download/diveintopython-exampleszh-cn-5.4b.zip
接下來將它解壓縮到c:\python\sample
然後開啟eclipse,將滑鼠指標移到原本的Helloworld專案上的src,按下滑鼠右鍵,選[New]/[Folder],如下圖所示:
接下來就會出現如下圖的畫面,請先點選[Advance],然後勾選[Link to folder in the file system],這表示將該資料夾設定為捷徑的方式來存取,最後在底下的空格內輸入c:\python\sample或是點選[Browse]取選取c:\python\sample資料夾
接下來請點選並開啟sample內的odbchelper.py檔案,最後再點選[Run]/[Run As]/[Python Run],來執行此odbchelper.py檔案,結果就會顯示出pwd=secret;database=master;uid=sa;server=mpilgrim
畫面如下所示:
列出odbchelper.py檔案如下:
"""odbchelper.py sample script
This program is part of "Dive Into Python", a free Python book for
experienced programmers. Visit http://diveintopython.org/ for the
latest version.
All this stuff at the top of the script is just optional metadata;
the real code starts on the "def buildConnectionString" line
"""
__author__ = "Mark Pilgrim (mark@diveintopython.org)"
__version__ = "$Revision: 1.2 $"
__date__ = "$Date: 2004/05/05 21:57:19 $"
__copyright__ = "Copyright (c) 2001 Mark Pilgrim"
__license__ = "Python"
def buildConnectionString(params):
"""Build a connection string from a dictionary
Returns string.
"""
return ";".join(["%s=%s" % (k, v) for k, v in params.items()])
if __name__ == "__main__":
myParams = {"server":"mpilgrim", \
"database":"master", \
"uid":"sa", \
"pwd":"secret"
}
print buildConnectionString(myParams)
呵呵!這算是我們除了Hello World的第一支程式吧!
請練習看看吧!
沒錯!Ubuntu內建就有Python了!
因為擔心太少人用Ubuntu了!
所以才用Windows環境介紹