マニュアル ・ 教材関係

.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()

python で正規表現を使う方法

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

PyAV

python-pptx

Progate

参考 URL


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