解決missing config-win.h & mysqlclient.lib.的問題
|
2016年2月23日 星期二
Python mysql library安裝
2016年2月15日 星期一
Python standard library string
python standard libray string
提供了一些字串操作基本功能
提供了一些字串操作基本功能
str.translate(table[, deletechars])
translate可以依據table來轉換str
如果轉換的目標是None,則match的字元就會被刪除
>>> 'read this short text'.translate(None, 'aeiou') 'rd ths shrt txt'
參考網址https://docs.python.org/2.7/library/string.html?highlight=translate#module-string
python standard library os
python standard library裡提供os這個module
可以進行os的一些基本操作
例如取得資料夾底下的檔案名
os.listdir(path)
列出路徑下,所有檔案名字
os.rename(src,dst)
將src檔名改成dst
os.getcwd( )
取得work directory 路徑
os.chdir(path)
改變work directory 路徑
參考網址
https://docs.python.org/2/library/os.html
可以進行os的一些基本操作
例如取得資料夾底下的檔案名
os.listdir(path)
列出路徑下,所有檔案名字
os.rename(src,dst)
將src檔名改成dst
os.getcwd( )
取得work directory 路徑
os.chdir(path)
改變work directory 路徑
參考網址
https://docs.python.org/2/library/os.html
2016年2月11日 星期四
python escape convert
要將字串轉成escape的型式
程式碼如下
def escape_covert(s):
for (i, o) in ( ('&', '&'),
('>', '>'),
('<', '<'),
('"', '"'),
):
s = s.replace(i, o)
return s
要注意 ('&', '&')要放第一個
否則其他escape charater
轉換完的&會被轉成'&
造成錯誤
但有更簡便的做法
就是import python的standard library cgi
import cgi
def escape_covert(s):
return cgi.escape(s,quote=True)
參考網址
https://docs.python.org/2/library/cgi.html
程式碼如下
def escape_covert(s):
for (i, o) in ( ('&', '&'),
('>', '>'),
('<', '<'),
('"', '"'),
):
s = s.replace(i, o)
return s
要注意 ('&', '&')要放第一個
否則其他escape charater
轉換完的&會被轉成'&
造成錯誤
但有更簡便的做法
就是import python的standard library cgi
import cgi
def escape_covert(s):
return cgi.escape(s,quote=True)
參考網址
https://docs.python.org/2/library/cgi.html
HTML escape characters
有時候在輸入字串時
字串裡的字會跟HTML TAG
相同而造成把字串當成HTML TAG
結果網頁輸出錯誤的內容
這時候就要用escape characters
較常使用的escape characters
- Space
- " "
- & &
- < <
- = ɥ
- > >
| Symbol | Entity Name |
|---|---|
| € | € |
| Space | |
| " | " |
| & | & |
| < | < |
| = | = |
| > | > |
| Non-breaking space | |
| ¡ | ¡ |
| ¢ | ¢ |
| £ | £ |
| ¤ | ¤ |
| ¥ | ¥ |
| ¦ | ¦ |
| § | § |
| ¨ | ¨ |
| © | © |
| ª | ª |
| ¬ | ¬ |
| | ­ |
| ® | ® |
| ¯ | ¯ |
| ° | ° |
| ± | ± |
| ² | ² |
| ³ | ³ |
| ´ | ´ |
| µ | µ |
| ¶ | ¶ |
| · | · |
| ¸ | ¸ |
| ¹ | ¹ |
| º | º |
| » | » |
| ¼ | ¼ |
| ½ | ½ |
| ¾ | ¾ |
| ¿ | ¿ |
| À | À |
| Á | Á |
| Â | Â |
| Ã | Ã |
| Ä | Ä |
| Å | Å |
| Æ | Æ |
| Ç | Ç |
| È | È |
| É | É |
| Ê | Ê |
| Ë | Ë |
| Ì | Ì |
| Í | Í |
| Î | Î |
| Ï | Ï |
| Ð | Ð |
| Ñ | Ñ |
| Ò | Ò |
| Ó | Ó |
| Ô | Ô |
| Õ | Õ |
| Ö | Ö |
| × | × |
| Ø | Ø |
| Ù | Ù |
| Ú | Ú |
| Û | Û |
| Ü | Ü |
| Ý | Ý |
| Þ | Þ |
| ß | ß |
| à | à |
| á | á |
| â | â |
| ã | ã |
| ä | ä |
| å | å |
| æ | æ |
| ç | ç |
| è | è |
| é | é |
| ê | ê |
| ë | ë |
| ì | ì |
| í | í |
| î | î |
| ï | ï |
| ð | ð |
| ñ | ñ |
| ò | ò |
| ó | ó |
| ô | ô |
| õ | õ |
| ö | ö |
| ÷ | ÷ |
| ø | ø |
| ù | ù |
| ú | ú |
| û | û |
| ü | ü |
| ý | ý |
| þ | þ |
Python string formatting
Python string formatting有二種
% 和 format method
%是比較舊的方式
建議使用format,比較恰當
在讀程式時較易理解
% 和 format method
%是比較舊的方式
建議使用format,比較恰當
在讀程式時較易理解
s1 = "John!"
s2 = "love"
print "i am %s" % s1 #i am John
print "i am {0}".format(s1) #i am John
print "with %(kwarg)s!" % {'kwarg':sub2} #with love
print "with {kwarg}!".format(kwarg=sub2) #with love
2016年2月10日 星期三
HTML select
<select>可以用做下拉是選單
搭配<option>做為選擇的值
而query parameter就是option的值
跟checkbox和radio不同
query parameter一定有值
代表至少會是其中一個option裡的值
<form action="/testform">
<select name="q">
<option>one</option>
<option>two</option>
<option>three</option>
</select>
<input type="submit">
</form>
HTML lable
要想在checkbox或在radio的選項
顯示選項的提示
可以使用<lable>
把<input>放在lable
在input前面顯示提示及可
<form>
<lable>
one
<input type="checkbox" name="q">
</lable>
<lable>
two
<input type="checkbox" name="s">
</lable>
<lable>
three
<input type="checkbox" name="r">
</lable>
<input type="submit">
</form>
<form>
<lable>
one
<input type="radio" name="q" value="one">
</lable>
<lable>
two
<input type="radio" name="q" value="two">
</lable>
<lable>
three
<input type="radio" name="q" value="three">
</lable>
<input type="submit">
</form>
顯示選項的提示
可以使用<lable>
把<input>放在lable
在input前面顯示提示及可
<form>
<lable>
one
<input type="checkbox" name="q">
</lable>
<lable>
two
<input type="checkbox" name="s">
</lable>
<lable>
three
<input type="checkbox" name="r">
</lable>
<input type="submit">
</form>
<form>
<lable>
one
<input type="radio" name="q" value="one">
</lable>
<lable>
two
<input type="radio" name="q" value="two">
</lable>
<lable>
three
<input type="radio" name="q" value="three">
</lable>
<input type="submit">
</form>
HTML input radio
<form>
<input type="radio" name="q" value="one">
<input type="radio" name="q" value="two">
<input type="radio" name="q" value="three">
<input type="submit">
</form>
<input type="radio" name="q" value="one">
<input type="radio" name="q" value="two">
<input type="radio" name="q" value="three">
<input type="submit">
</form>
HTML HTTP GET V.S POST
HTTP requset 有二種送參數的method
GET 和 POST
下表為二者的比較
GET 和 POST
下表為二者的比較
| GET | POST |
|---|---|
|
|
由表可知二者的不同
在應用上也就不同
必需依據其特性來使用
否則在應用上會造成錯誤或不便
HTML form tag & input tag
form tag裡面放input tag
input tag則可以輸入資料
而且可以送出
例子
<form action="http://www.google.com/search">
<input name="q">
<input type="submit">
</form>
input tag則可以輸入資料
而且可以送出
例子
<form action="http://www.google.com/search">
<input name="q">
<input type="submit">
</form>
HTTP URL RESPONSE
瀏覽器向伺服器請求資料
伺服器就會RESPONSE回去
同樣的跟request一樣
有標頭檔
HTTP/ 1.1 200 OK
Date: 2016 2 10
Content-Type: text/html
Content-Length: 1539
第一行的200代表的是HTTP STATUS CODE
200表示請求正常
標頭檔後面就是請求的資料
伺服器就會RESPONSE回去
同樣的跟request一樣
有標頭檔
HTTP/ 1.1 200 OK
Date: 2016 2 10
Content-Type: text/html
Content-Length: 1539
第一行的200代表的是HTTP STATUS CODE
200表示請求正常
標頭檔後面就是請求的資料
2016年2月9日 星期二
HTML URL HTTP
HTTP是網路最常見的協定之一
全名是HyperText Transfer Protocol
這個協定包含二個method
GET和POST
GET是請求檔案
POST則是傳資料到server
http://example.com/profile.html?user=jack&pwd=123#page=1
這行的url,HTTP會使用GET path http-version的參數
所以會變成GET profile.html?user=jack&pwd http/1.1
會向host example.com請求
注意路徑也包括了query parameters ?user=jack&pwd
除此之外還會傳送header給host
header的型式,為標頭名: 值
Host:www.example.com
user-Agent: chrome
user-Agent指的是使用者用什麼來瀏覽網頁或請求這個網頁
全名是HyperText Transfer Protocol
這個協定包含二個method
GET和POST
GET是請求檔案
POST則是傳資料到server
http://example.com/profile.html?user=jack&pwd=123#page=1
這行的url,HTTP會使用GET path http-version的參數
所以會變成GET profile.html?user=jack&pwd http/1.1
會向host example.com請求
注意路徑也包括了query parameters ?user=jack&pwd
除此之外還會傳送header給host
header的型式,為標頭名: 值
Host:www.example.com
user-Agent: chrome
user-Agent指的是使用者用什麼來瀏覽網頁或請求這個網頁
HTML URL PORT
網頁的URL通常省略port
例如輸入
http://example.com/about.html
實際上會在host後面加上 ':'加上 port名稱,做為完整的url
http://example.com:80/about.html
如果沒有指定port,會自動指定port為80
而8080這個port是常見
用來做本機網頁測試
瀏覽網頁用的
通常使用
http://localhost:8080
例如輸入
http://example.com/about.html
實際上會在host後面加上 ':'加上 port名稱,做為完整的url
http://example.com:80/about.html
如果沒有指定port,會自動指定port為80
而8080這個port是常見
用來做本機網頁測試
瀏覽網頁用的
通常使用
http://localhost:8080
HTML URL
一般網頁的URL組成
protocol://host/path 的格式
例如
http://example.com/about.html
根據這個URL,可以向example.com找到about.html
而一般省略path只有
http://example.com 這樣,通常代表要求首頁
而一般首頁會使用index.html
protocol://host/path 的格式
例如
http://example.com/about.html
根據這個URL,可以向example.com找到about.html
而一般省略path只有
http://example.com 這樣,通常代表要求首頁
而一般首頁會使用index.html
HTML URL Fragments
URL的 Fragments,用'#'符號來表示
他的用處是可以target網頁裡的指定element
通常Fragments加在query parameter後面
例如
http://example.com/profile.html?user=jack&pwd=123#page=1
與query parameter同樣的可以傳入多個參數
他的用處是可以target網頁裡的指定element
通常Fragments加在query parameter後面
例如
http://example.com/profile.html?user=jack&pwd=123#page=1
與query parameter同樣的可以傳入多個參數
HTML URL-Query Parameters(Get Parameters)
在瀏覽器根據url的連結
提供該網頁的伺服器
例如
http://example.com/profile.html
這個url獲取profile.html
而我們可以在url後面加參數給伺服器使用
如何加參數,首先在最後的路徑加入'?'符號
之後就是參數,可以加入數個參數
而參數的型式
參數名 = 值
參數與參數間用'&'符號
http://example.com/profile.html?user=jack&pwd=123
上面就會傳user和pwd二個參數給伺服器
而值分別為jack和123
提供該網頁的伺服器
例如
http://example.com/profile.html
這個url獲取profile.html
而我們可以在url後面加參數給伺服器使用
如何加參數,首先在最後的路徑加入'?'符號
之後就是參數,可以加入數個參數
而參數的型式
參數名 = 值
參數與參數間用'&'符號
http://example.com/profile.html?user=jack&pwd=123
上面就會傳user和pwd二個參數給伺服器
而值分別為jack和123
HTML inline element V.S block element
在HTML檔裡,純文字的資料
在字元之間,不管是空幾格空白
或是換行,都會被看成只空一格空白
所以想要換行可以使用<br> tag或是<p> tag
<br>換行
This is first line.
This is second line.
<p>換行
This is first line.
This is second line.
這二者不同之處在於
<br>處理方式是
This is first line.(\n->換行)This is second line.
直接在行與行之間插入element,並處理
而<p> tag的方式是
element型成一個block把element和element之隔開
其他inline element有
在字元之間,不管是空幾格空白
或是換行,都會被看成只空一格空白
所以想要換行可以使用<br> tag或是<p> tag
<br>換行
This is first line.
This is second line.
<p>換行
This is first line.
This is second line.
這二者不同之處在於
<br>處理方式是
This is first line.(\n->換行)This is second line.
直接在行與行之間插入element,並處理
而<p> tag的方式是
This is first line.
This is second line.
element型成一個block把element和element之隔開
其他inline element有
- <b>粗體
- <em>斜體
- <img>圖片
- <span>
- <a>連結
- <br>換行
2016年2月8日 星期一
Python Standard Library time
Python Standard Library裡有time module提供相關的功能
例如
想要暫停現在的動作可以使用sleep
time.sleep(1)
取得現在的時間可以用ctime
time.ctime( )
會回傳 星期 月份 日期 時:分:秒 年的型式,例如Mon Feb 08 23:24:26 2016
參考網站
https://docs.python.org/2/library/time.html
例如
想要暫停現在的動作可以使用sleep
time.sleep(1)
程式就會暫停1秒,再執行後面的動作
取得現在的時間可以用ctime
time.ctime( )
會回傳 星期 月份 日期 時:分:秒 年的型式,例如Mon Feb 08 23:24:26 2016
參考網站
https://docs.python.org/2/library/time.html
Python Standard Library webbrowser
Python Standard Library裡有webbrowser這個module
webbrowser提供簡單的function,來執行瀏覽器
例如
就會打開瀏覽器,瀏覽輸入url的網址的網頁
如果要指定特定瀏覽器來瀏覽
可以使用webbrowser.get來得到object
再使用這個object來呼叫open function
firefox = webbrowser.get('C:/Program Files (x86)/Mozilla Firefox/firefox.exe %s')
firefox.open("www.google.com")
這裡要注意的是傳入get function裡的路徑
與windows裡路徑使用' \ ' 不同
要使用unix-style的' / '才有辦法找到路徑
參考網站
https://docs.python.org/2/library/webbrowser.html
webbrowser提供簡單的function,來執行瀏覽器
例如
webbrowser.open(url, new=0, autoraise=True)就會打開瀏覽器,瀏覽輸入url的網址的網頁
如果要指定特定瀏覽器來瀏覽
可以使用webbrowser.get來得到object
再使用這個object來呼叫open function
firefox = webbrowser.get('C:/Program Files (x86)/Mozilla Firefox/firefox.exe %s')
firefox.open("www.google.com")
這裡要注意的是傳入get function裡的路徑
與windows裡路徑使用' \ ' 不同
要使用unix-style的' / '才有辦法找到路徑
參考網站
https://docs.python.org/2/library/webbrowser.html
2016年2月6日 星期六
Http status code
向ip請求網頁文字,server會回傳標頭。
其中標頭裡有status code這一個欄位。
它代表了這次的請求結果如何。
下表是常見的代碼以及它代表的狀況。
其中標頭裡有status code這一個欄位。
它代表了這次的請求結果如何。
下表是常見的代碼以及它代表的狀況。
| code | 結果 |
|---|---|
| 200 | 請求成功,網頁正常 |
| 301 | 請求的網頁被移到新的位置上 |
| 404 | 請求失敗,請求的網頁沒有在伺服器上 |
訂閱:
意見 (Atom)