覺得學習這本書應該有筆記,所以就從這里開始吧。
學習資料:
1.《笨辦法學Python》(承德-至陽整理 2013/7/19)
2.《Learn Python The Hard Way,3rd Edition》 (Zed A. Shaw 2010)
一、準備學習環境
(二)下載集成開發環境,我使用的是EditPlus4.1,因其為收費版,怎么找能用的,你懂的。
配置集成開發環境:
1.打開EditPlus,點擊 工具->配置用戶工具
點擊 組名,新建一個python組,點擊 添加工具->應用程序,按上圖所示在菜單文字、命令、參數、初始目錄、動作中添加或選擇相應的內容。
2.為了可以捕捉錯誤輸出和輸出結果,在上圖 動作 下拉菜單中選擇捕捉輸出,點擊 輸出模板,按下圖所示填寫相關內容。
3.安裝EditPlus的python插件,下載地址http://www.editplus.com/files/pythonfiles.zip,解壓后復制到EditPlus的安裝目錄即可,如果軟件自帶可不覆蓋,使用最新的即可。插件的主要功能是讓EditPlus支持語法高亮和函數自動補全功能。
讓它們發揮作用: 選擇 工具->配置用戶工具,點選左側選項卡中的文件->設置&語法,右側 文件類型 選擇 python,如下圖所示:
語法文件:python_extd.stx(也就是editplus目錄下面的解壓的文件)
自動完成:python.acp
4.點擊 上圖的 函數模板修改一下這里的正則表達式為:[ \t]*def[ \t].+: 確定之后再點擊 Tab/縮進,然后填寫相應的東西。這里主要是為了讓python代碼可以自動隨進,我們設置了默認是四個空格,這樣寫出來的代碼就很漂亮了!
5.最后一步可以設置一下python的默認模板,它的作用是讓你新建文件更快捷。
在EditPlus的安裝目錄新建一個template.py文件,內容如下:
#!/usr/bin/python
# -*- coding: utf-8 -*-
點擊 工具->配置用戶工具,在左側的選項卡中點擊 文件->模板,點擊右側的 添加按鈕,在彈出的對話框中選擇上邊新建的template.py文件,菜單文本 中填寫 python,點擊 確定 即可。
6.最后建立一個養眼的顏色方案。
新建 EditPlus顏色配置.ini 文件,內容如下:
[Colors\Text]
Foreground=14738148
Background=3420457
Default=0
[Colors\Embedded script]
Foreground=15000288
Default=0
[Colors\Active line]
Foreground=15000288
Background=2699572
Default=0
[Colors\Text selection]
Background=16512
Default=0
[Colors\Line number]
Foreground=11723505
Background=3420457
Default=0
[Colors\Ruler]
Foreground=11723505
Background=3420457
Default=0
[Colors\Cursor indicator]
Foreground=15000288
Background=2699572
Default=0
[Colors\Output window]
Foreground=16777215
Background=2699572
Default=0
[Colors\Tabs and spaces]
Foreground=30444
Default=0
[Colors\Line break]
Foreground=1638527
Default=0
[Colors\Column marker]
Foreground=15593186
Default=0
[Colors\Matching Brace]
Foreground=11221743
Background=2699572
Default=0
[Colors\Folding mark -]
Foreground=15000288
Background=2699572
Default=0
[Colors\Folding mark +]
Foreground=15000288
Background=2699572
Default=0
[Colors\URL]
Foreground=11635815
Default=0
[Colors\Markers]
Background=2699572
Default=0
[Colors\Matching words]
Background=3420457
Default=0
[Colors\Keyword 1]
Foreground=6539155
Default=0
[Colors\Keyword 2]
Foreground=11635815
Default=0
[Colors\Keyword 3]
Foreground=30444
Default=0
[Colors\Keyword 4]
Foreground=7163599
Default=0
[Colors\Keyword 6]
Foreground=11635815
Default=0
[Colors\Keyword 7]
Foreground=6709465
Default=0
[Colors\Line comment]
Foreground=9669757
Default=0
[Colors\Line comment 2]
Foreground=10063553
Default=0
[Colors\Block comment]
Foreground=10063553
Default=0
[Colors\Block comment 2]
Foreground=10063553
Default=0
[Colors\Quotation]
Foreground=30444
Default=0
[Colors\Quotation 2]
Foreground=30444
Default=0
[Colors\Keyword 8]
Foreground=30444
Default=0
[Colors\Keyword 9]
Foreground=30444
Default=0
[Colors\Keyword 10]
Foreground=30444
Default=0
到EditPlus安裝目錄觀察其顏色配置文件的文件名,我的是editplus_u,將其改名,將上邊的ini文件改成該名字復制到這里就可以了。
下面帶你去看一下代碼效果,選擇菜單欄的新建就可以看到有一個python選項了.在這里你簡單寫點代碼測試一下你的配置環境有沒有成功。看到報錯信息,在下面的錯誤上面雙擊就可以跳到錯誤行了很方便,不然上千行你去找累啊!寫完之后保存按ctrl+1就可以運行代碼了!
要注意的是需要輸入參數和在運行中需要人機交互的程序,還是需要在控制臺環境下運行,我還沒找到更好的方法。
(三)我有時候喜歡在多個地點學習,配置了多臺計算機,怎么能同步學習進度呢,我采用了使用git的方法,下面講一下我自己琢磨的git的使用。(參考了廖雪峰的git教程)
1.在gtihub上注冊賬號。
2.如果是linux系統,一般內置git,直接使用即可,如果沒有,google或百度之進行安裝就行了;如果是windows操作系統需要安裝git支持程序,win7以上可以到Git for Windows下載git的客戶端,如果是winXP可以到Babun - a windows shell you will love!下載babun,使用方法可以自己查看幫助文檔。這里只講git的配置和使用方法。
3.建立本地git賬號
git config --global user.name 你的名字
git config --global user.email 你的郵箱
4.在本地生成ssh公鑰和私鑰
ssh-keygen -t rsa -C 你的郵箱名(也可以試試別的)
設置ssh文件夾權限
chmod 755 ~/.ssh/
chmod 600 ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa.pub
chmod 644 ~/.ssh/known_hosts
要注意的是.ssh文件夾會因為系統不同位置不同,具體可google或百度。known_hosts可能一開始會沒有,在你使用git上傳代碼之后會自動生成,之后就可以設置了。
將生成的公鑰id_rsa.pub中的內容上傳到github,即 登錄你的github賬號 -> settings,在出現的頁面左側點擊SSH and GPG keys,
點擊 New GPG key,將公鑰粘貼到出現的頁面里提交即可。
5.幾種git的使用方法:
(1)本地無任何內容,克隆一個完整的工程:
git clone git@github.com:你的賬號/LearnPythonTheHardWay.git
(2)本地已有工程,更新到最新:
git fetch --all
git reset --hard LearnPythonTheHardWay/master
(3)本地新建的工程上傳:
第一次執行以下命令:
git init
git add . #(所有內容添加到倉庫)
git commit -m "說明" #告訴git修改版本提交
git remote add LPTHW git@github.com:你的賬號/LearnPythonTheHardWay.git
git push -u LPTHW master
之后每次提交執行以下命令:
git add . #(所有內容添加到倉庫)
git commit -m "說明" #告訴git修改版本提交
git push -u LPTHW master
至此開發環境已全部配置完畢,可以開始學習之旅了。