留下快樂和驚喜 與過去近一點

星期五, 12月 25, 2015

看 CNN Student News 學英文

對於要練習英文,CNN Student News 會是其中一個溝道,不過CNN 的語速比較快和沒有字幕,比較難跟,好在現在網上的資源豐富,在youtube可以找到有字幕的CNN Student News.



scripts: 

Welcome to our last edition of CNN Student News for 2015.
I'm Carl Azuz. And Fridays(每星期五) are awesome (adj. 真棒, 正) ! 
For the past few days, our year end review series has looked back at some of the stories that made headlines since January. Teachers, you could find all of our shows in the archive section of CNNStudentNews.com.

星期三, 9月 30, 2015

Python 3.5.0 urllib 用法

在網上搜索使用Python語言的網絡爬蟲(Crawler)程式碼時,經常會出現導入(import) "urllib" 及 "urllib2" 模組(module)的程式碼。

但是在 Python 3.X 的版本中,將 "urllib" 和 "urllib2" 模組合併為 "urllib" 下的模組,分別是"urllib.error","urllib.request","urllib.response",還有 "urllib.parse" 及 "urllib.robotparser" 。

不過要留意導入 "urllib" 是不會同時導入 urllib 下的模組。
以下會用 Python 內建函數(Built-in Function)中的 "dir()" 作示範。
# Print every function inside a module
import urllib               # Imports the urllib module
print (dir(urllib))         # Prints urllib

# Print every function inside a module
import urllib.error         # Imports the urllib.error module
print (dir(urllib.error))   # Prints urllib.error

# Print every function inside a module
import urllib.request       # Imports the urllib.request module
print (dir(urllib.request)) # Prints urllib.request

如要導入模組,需要指明模組的名稱,如下
import urllib.request
import urllib.response
import urllib.error
在 Python 3.X 中,以下左方的語法要 改成 右方的語法
urllib2.urlopen() 改成 urllib.request.urlopen()
urllib2.Request() 改成 urllib.request.Request()

想了解更多,可參考以下英文教學。
Python 3.X Porting Guide

星期二, 9月 15, 2015

Python 3.5.0 入門

在 windows 的環境下,python 是需要安裝,而在 Mac 和 Unix 的環境是內建的。

第一步: 在 Windows 安裝 python

Python 的安裝檔可以在官網 (https://www.python.org/) 下載,目前最新的穩定版本為 3.5.0。由於本人的電腦環境為 32bit 的 windows10,所以下載 "Python 3.5.0 - 2015-09-13 - Windows x86 executable installer"。

星期六, 9月 12, 2015

Copyright © Matt Ko in UK 旅英紀錄 | Powered by Blogger

Design by Matthew Ko | Blogger Theme by NewBloggerThemes.com