note

python tips

コマンドラインパーサー

from argparse import ArgumentParser

ファイルアクセス

withでclose処理を省略デキル

#!/usr/bin/env python
#coding:utf-8

import sys

with open('test1.txt') as lines:
    for line in lines:
        text = line.rstrip('\r\n')
        print(text, end='')

参考

文末の改行文字を消す

text.rstrip('\r\n')

参考

print

python3だとprint(text, end=’‘)が使えるがpython2.x系は使えない そのときは以下の構文を先頭で宣言すればprint関数が上書きされる

from __future__ import print_function

参考