SlideShare une entreprise Scribd logo
1  sur  27
2. 從 REPL 到 IDE
• 學習目標
– 使用 REPL
– 設定原始碼檔案編碼
– 基本模組與套件管理
– 認識 IDE 的使用
2
使用 REPL
• REPL(Read-Eval-Print Loop,又稱為
Python Shell)
3
4
取得協助訊息
5
6
7
8
• 如果要離開 REPL 環境,可以執行 quit()
函式
9
撰寫 Python 原始碼
10
11
12
哈囉!世界!
• 事物的複雜度不會憑空消失,只會從一個
事物轉移到另一個事物
13
UTF-8
• Python 3 之後,python 直譯器預期的原
始碼檔案編碼必須是 UTF-8
14
• 使用註解設定編碼資訊
• 在 Python 原始碼檔案中,# 開頭代表這
是一行註解
15
• 到其他的編碼設定方式
• python 直譯器只要在註解中看到
coding=<encoding name> 或者
coding: <encoding name> 出現
# -*- coding: Big5 -*-
# vim: set fileencoding=Big5 :
16
簡介模組
• 每個 .py 檔案本身就是一個模組
• 直接重用先前撰寫好的 hello2.py 檔案
17
• Python 本身提供有標準程式庫
18
• 如果有多個模組需要 import,除了逐行
import 之外,也可以在單一行中使用逗號
「,」來區隔模組
• 在 __builtins__模組中的函式、類別等
名稱,都可以不用 import 直接取用,而
且不用加上模組名稱作為前置
import sys, email
19
設定 PYTHONPATH
• 可以設定 PYTHONPATH 環境變數來解決這
個問題:
20
21
• 想要動態地管理模組的尋找路徑, 也可以
透過程式變更 sys.path 的內容來達到
22
使用套件管理模組
• 模組也應該分門別類加以放置
• 一定要有一個__init__.py 檔案,該資料夾
才會被視為一個套件
• 在套件的進階管理中,__init__.py 中其實
也可以撰寫程式
23
• 套件名稱會成為名稱空間的一部份
• 可以建立多層次的套件,每個擔任套件的
資料夾與子資料夾中,各要有一個
__init__.py
24
import as、from import
• import as
• from import
25
• 如果有多個名稱想要直接匯入目前模組,
除了逐行 from import 之外,也可以在
單一行中使用逗號「,」來區隔
• 更偷懶一點(不建議)
26
使用IDE
• PyCharm(www.jetbrains.com/pycharm/)
• PyDev(www.pydev.org/)
• Komodo IDE(komodoide.com/)
• Spyder
(code.google.com/archive/p/spyderlib/)
• WingIDE(wingware.com/)
• NINJA-IDE(www.ninja-ide.org/)
• Python Tools for Visual Studio
(pytools.codeplex.com/)
27

Contenu connexe

Tendances

Python 编程艺术
Python 编程艺术Python 编程艺术
Python 编程艺术
wilhelmshen
 
Erlang jiacheng
Erlang jiachengErlang jiacheng
Erlang jiacheng
Air-Smile
 
Erlang开发及应用
Erlang开发及应用Erlang开发及应用
Erlang开发及应用
litaocheng
 

Tendances (9)

Python 编程艺术
Python 编程艺术Python 编程艺术
Python 编程艺术
 
Erlang jiacheng
Erlang jiachengErlang jiacheng
Erlang jiacheng
 
Php Extension--yahoo(Cc0cc)
Php Extension--yahoo(Cc0cc)Php Extension--yahoo(Cc0cc)
Php Extension--yahoo(Cc0cc)
 
Python系列3
Python系列3Python系列3
Python系列3
 
Free rtos workshop1@nuu
Free rtos workshop1@nuuFree rtos workshop1@nuu
Free rtos workshop1@nuu
 
Python系列4
Python系列4Python系列4
Python系列4
 
[ZigBee 嵌入式系統] ZigBee Architecture 與 TI Z-Stack Firmware
[ZigBee 嵌入式系統] ZigBee Architecture 與 TI Z-Stack Firmware[ZigBee 嵌入式系統] ZigBee Architecture 與 TI Z-Stack Firmware
[ZigBee 嵌入式系統] ZigBee Architecture 與 TI Z-Stack Firmware
 
Python系列1
Python系列1Python系列1
Python系列1
 
Erlang开发及应用
Erlang开发及应用Erlang开发及应用
Erlang开发及应用
 

Similaire à 從 REPL 到 IDE

简单Pthon教程
简单Pthon教程简单Pthon教程
简单Pthon教程
junjun chen
 
Adorable python
Adorable pythonAdorable python
Adorable python
Rhythm Sun
 
Tiptop gp 5.1 setup_instructions
Tiptop gp 5.1 setup_instructionsTiptop gp 5.1 setup_instructions
Tiptop gp 5.1 setup_instructions
guest994aeb5
 
Web scraping入門1
Web scraping入門1Web scraping入門1
Web scraping入門1
兆欽 丘
 
Python简明教程
Python简明教程Python简明教程
Python简明教程
ingong
 

Similaire à 從 REPL 到 IDE (16)

2. 從 REPL 到 IDE
2. 從 REPL 到 IDE2. 從 REPL 到 IDE
2. 從 REPL 到 IDE
 
Python01
Python01Python01
Python01
 
執行緒與並行API
執行緒與並行API執行緒與並行API
執行緒與並行API
 
简单Pthon教程
简单Pthon教程简单Pthon教程
简单Pthon教程
 
建置Python開發環境
建置Python開發環境建置Python開發環境
建置Python開發環境
 
Learn python 2 - Real World Case
Learn python 2 - Real World CaseLearn python 2 - Real World Case
Learn python 2 - Real World Case
 
Java Tutorial:Learn Java in 06:00:00
Java Tutorial:Learn Java in 06:00:00Java Tutorial:Learn Java in 06:00:00
Java Tutorial:Learn Java in 06:00:00
 
Adorable python
Adorable pythonAdorable python
Adorable python
 
CH10:輸入輸出
CH10:輸入輸出CH10:輸入輸出
CH10:輸入輸出
 
Continuous Delivery Workshop with Ansible x GitLab CI
Continuous Delivery Workshop with Ansible x GitLab CIContinuous Delivery Workshop with Ansible x GitLab CI
Continuous Delivery Workshop with Ansible x GitLab CI
 
Tiptop gp 5.1 setup_instructions
Tiptop gp 5.1 setup_instructionsTiptop gp 5.1 setup_instructions
Tiptop gp 5.1 setup_instructions
 
Oracle Security 101
Oracle Security 101Oracle Security 101
Oracle Security 101
 
Web scraping入門1
Web scraping入門1Web scraping入門1
Web scraping入門1
 
Python简明教程
Python简明教程Python简明教程
Python简明教程
 
2, OCP - installing and creating a database
2, OCP - installing and creating a database2, OCP - installing and creating a database
2, OCP - installing and creating a database
 
Continuous Delivery with Ansible x GitLab CI (2e)
Continuous Delivery with Ansible x GitLab CI (2e)Continuous Delivery with Ansible x GitLab CI (2e)
Continuous Delivery with Ansible x GitLab CI (2e)
 

Plus de Justin Lin

Plus de Justin Lin (20)

Ch14 簡介 Spring Boot
Ch14 簡介 Spring BootCh14 簡介 Spring Boot
Ch14 簡介 Spring Boot
 
Ch13 整合 Spring MVC/Security
Ch13 整合 Spring MVC/SecurityCh13 整合 Spring MVC/Security
Ch13 整合 Spring MVC/Security
 
Ch12 Spring 起步走
Ch12 Spring 起步走Ch12 Spring 起步走
Ch12 Spring 起步走
 
Ch11 簡介 JavaMail
Ch11 簡介 JavaMailCh11 簡介 JavaMail
Ch11 簡介 JavaMail
 
Ch10 Web 容器安全管理
Ch10 Web 容器安全管理Ch10 Web 容器安全管理
Ch10 Web 容器安全管理
 
Ch09 整合資料庫
Ch09 整合資料庫Ch09 整合資料庫
Ch09 整合資料庫
 
Ch08 自訂標籤
Ch08 自訂標籤Ch08 自訂標籤
Ch08 自訂標籤
 
Ch07 使用 JSTL
Ch07 使用 JSTLCh07 使用 JSTL
Ch07 使用 JSTL
 
Ch06 使用 JSP
Ch06 使用 JSPCh06 使用 JSP
Ch06 使用 JSP
 
Ch05 Servlet 進階 API、過濾器與傾聽器
Ch05 Servlet 進階 API、過濾器與傾聽器Ch05 Servlet 進階 API、過濾器與傾聽器
Ch05 Servlet 進階 API、過濾器與傾聽器
 
Ch04 會話管理
Ch04 會話管理Ch04 會話管理
Ch04 會話管理
 
Ch03 請求與回應
Ch03 請求與回應Ch03 請求與回應
Ch03 請求與回應
 
Ch02 撰寫與設定 Servlet
Ch02 撰寫與設定 ServletCh02 撰寫與設定 Servlet
Ch02 撰寫與設定 Servlet
 
CH1. 簡介 Web 應用程式
CH1. 簡介 Web 應用程式CH1. 簡介 Web 應用程式
CH1. 簡介 Web 應用程式
 
14. 進階主題
14. 進階主題14. 進階主題
14. 進階主題
 
13.並行、平行與非同步
13.並行、平行與非同步13.並行、平行與非同步
13.並行、平行與非同步
 
12. 除錯、測試與效能
12. 除錯、測試與效能12. 除錯、測試與效能
12. 除錯、測試與效能
 
11. 常用內建模組
11. 常用內建模組11. 常用內建模組
11. 常用內建模組
 
10. 資料永續與交換
10. 資料永續與交換10. 資料永續與交換
10. 資料永續與交換
 
9. 資料結構
9. 資料結構9. 資料結構
9. 資料結構
 

從 REPL 到 IDE