2013年6月7日 星期五
wget https ERROR: The certificate of '*' is not trusted.
$ wget --no-check-certificate https://example.com/testfile.tgz
2013年6月6日 星期四
Python switch case
PHP :
Python :
Reference :
Python的switch…case语法 | vifix.cn
switch(lang)
{
case 'zh':
zhDo(argu);
break;
case 'jp':
jpDo(argu);
break;
default:
enDo(argu);
break;
}
Python :
try:
{
'zh': zhDo,
'jp': jpDo,
}[lang](argu)
except KeyError:
# default action
enDo
Reference :
Python的switch…case语法 | vifix.cn
2013年6月5日 星期三
2013年6月4日 星期二
Python Bottle 操作 MySQL 的幾種方式
1. bottle_mysql plugin
需寫 SQL 語句
需透過 bottle route 傳入 db 連結句柄,靈活度不高
bottle-mysql 0.1.1 : Python Package Index
2. 自己封裝 MySQLdb 類別
需寫 SQL 語句
function 可重用
bottle-linkshorter/linkshorter.py at master · denschub/bottle-linkshorter · GitHub
3.使用 ORM
需要定義每個表格、欄位資訊
功能較強大 (基本功能不需寫 SQL 語句、資料欄位驗証、安全過濾)
CURD.py | Tiny Python ORM for MySQL — CURD.py | Tiny Python ORM for MySQL
SQLAlchemy - The Database Toolkit for Python (powerful)
Reference :
What are some good Python ORM solutions? - Stack Overflow
需寫 SQL 語句
需透過 bottle route 傳入 db 連結句柄,靈活度不高
bottle-mysql 0.1.1 : Python Package Index
app = default_app()
db_plugin = mysql.Plugin(dbhost=DB_HOST, dbuser=DB_USER, dbpass=DB_PASS, dbname=DB_NAME, keyword='db') # default keyword is db
app.install(db_plugin)
2. 自己封裝 MySQLdb 類別
需寫 SQL 語句
function 可重用
bottle-linkshorter/linkshorter.py at master · denschub/bottle-linkshorter · GitHub
3.使用 ORM
需要定義每個表格、欄位資訊
功能較強大 (基本功能不需寫 SQL 語句、資料欄位驗証、安全過濾)
CURD.py | Tiny Python ORM for MySQL — CURD.py | Tiny Python ORM for MySQL
SQLAlchemy - The Database Toolkit for Python (powerful)
Reference :
What are some good Python ORM solutions? - Stack Overflow
2013年6月3日 星期一
Python MySQLdb query results with column name
conn = MySQLdb.Connect( host='localhost', user='root', passwd='', db='test',compress=1, cursorclass=MySQLdb.cursors.DictCursor)orcursor = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
Reference :
MySQL and accessing database results by field « Python recipes « ActiveState Code
Python auto import module from sub directory
import sys
sys.path.append('/your/module/directory')
from autoimp import *
your_module.test()
Some keywords :
import imp
imp.load_module
module = __import__("module")
globals().update(vars(module))
Reference :
python - When automatically importing modules from a subfolder, their imports fail - Stack Overflow
Some Notes on Importing Modules by Name
python - Dynamic importing of modules followed by instantiation of objects with a certain baseclass from said modules - Stack Overflow
Some Notes on Importing Modules by Name
python - Dynamic importing of modules followed by instantiation of objects with a certain baseclass from said modules - Stack Overflow
Python autoimp module
2013年6月2日 星期日
訂閱:
文章 (Atom)