マニュアル ・ 教材関係

.bashrc の設定(Ubuntu 18.04 のデフォルトを python3 系に指定)

alias python='python3'
alias pip='pip3'がある

.vimrc の設定 (python ファイルに対してだけ有効な設定、TABをスペース4に変更など)

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 の自動改行を無効化

文字列を指定したセパレータで分解する

python で正規表現を使う方法

import re
group()マッチした文字列を返す
start()マッチした文字列の開始位置を返す
end()マッチした文字列の終了位置を返す
span()マッチした文字列の (開始位置, 終了位置) のタプルを返す

Python 日付、時刻の処理 (外部モジュール dateutil)

SQLite

Open CV

pylint 関連

仮想環境の構築

PyAV

python-pptx

Progate

paiza

参考 URL


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS