マニュアル ・ 教材関係†
.vimrc 設定 (python ファイルに対してだけ有効)†
autocmd FileType python setl autoindent
autocmd FileType python setl smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
autocmd FileType python setl tabstop=8 expandtab shiftwidth=4 softtabstop=4
ファイル読み込み(コマンドライン引数でファイル名を指定、エラー処理付き)†
import sys
script_name = sys.argv[0]
try:
file_name = sys.argv[1]
file_desc = open(file_name, 'r')
except IndexError:
print 'Usage: %s TEXTFILE' % script_name
except IOError:
print '"%s" cannot be opened.' % file_name
else:
# ファイルを一行ずつ読み込む場合
for line in file_desc:
print line
# ファイル全体をまとめてリストに読み込む場合
lines = file_desc.readlines()
print lines
file_desc.close()
数字の整形(桁区切り、小数点の丸め)†
>>> "{:,}".format(1234.5678)
'1,234.5678'
>>> "{:,.2f}".format(1234.5678)
'1,234.57'
logging.debug("size = %s byte", "{:,}".format(vfp_size))
print の自動改行を無効化†
- print("abc","") のように空白文字を行末に付与する
文字列を指定したセパレータで分解する†
- split("セパレータ文字") で要素に分解されてリストに格納される
- split("セパレータ",N) で N 番目まで区切って、以下は分解しない
python で正規表現を使う方法†
import re
- re モジュールには正規表現パターンを使用した検索、置換、連結、分割などのメソッドがある
- これらのメソッドはマッチした文字列を返すものもあれば、MatchObject インスタンスを返すものがある
| group() | マッチした文字列を返す |
| start() | マッチした文字列の開始位置を返す |
| end() | マッチした文字列の終了位置を返す |
| span() | マッチした文字列の (開始位置, 終了位置) のタプルを返す |
SQLite†
Open CV†
pylint 関連†
Constant name "cols" doesn't conform to UPPER_CASE naming style
- 警告の最後の()内を~/.pylintrcのdisabledに追加すれば、その警告は消えてくれるらしい。
- スライドアスペクト指定
- # set slide aspect = 16:9
- prs.slide_width = 9144000
- prs.slide_height = 5143500
- スライドレイアウトの指定(スライドマスターのどの表示形式を使うか)
- prs.slide_layouts[0] = Title (presentation title slide)
- prs.slide_layouts[1] = Title and Content
- prs.slide_layouts[2] = Section Header (sometimes called Segue)
- prs.slide_layouts[3] = Two Content (side by side bullet textboxes)
- prs.slide_layouts[4] = Comparison (same but additional title for each side by side content box)
- prs.slide_layouts[5] = Title Only
- prs.slide_layouts[6] = Blank
- prs.slide_layouts[7] = Content with Caption
- prs.slide_layouts[8] = Picture with Caption
参考 URL†