2011-10-01から1ヶ月間の記事一覧

MySQLdb で like 検索

メモ。 Python の MySQLdb で like 検索を行う場合。 import MySQLdb connector = MySQLdb.connect( host=host, port=port, db=db, user=user, passwd=password, use_unicode=0, charset='utf8' ) cursor = connector.cursor() param = 'python' sql = """SE…

Jinja2 で number_format を使う

PHP の便利関数の一つに number_format というのがある。 PHP: number_format - Manual 同じ事を Python でやろうとすると、以下が見つかった。 number_format filter | Flask (A Python Microframework) http://ndiblog.mezquita.jp/archives/96 ロケールを…

Flask で debug=False 時にログを出力する

Flask で開発時は debug = True にし app.logger を使用するとログを標準出力する。 本番環境では標準出力じゃなくて、ファイルに出力するようにしてた。 import os import logging from logging.handlers import RotatingFileHandler from flask import Fla…

PostgreSQL の PL/Python を試してみる

PostgreSQL にはストアドプロシージャ(ファンクション)に Perl や Python といったスクリプト言語で記述できる。 これを使えば Perl/Python で外部のサーバにメッセージを飛ばせないかやってみた。 まずは MacPorts で PostgreSQL8.4 をインストール(9.x を…