Created
March 26, 2014 18:41
-
-
Save yuitest/9790289 to your computer and use it in GitHub Desktop.
引数やら標準入力やらで入ってきた文字を、テキトーにちょんぎって、改行して出力する。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
from __future__ import unicode_literals, print_function | |
import re | |
def separator(text): | |
for token in re.split(r'\t|\n|\r|,', text): | |
if token: | |
yield token | |
if __name__ == '__main__': | |
import sys | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('cols', metavar='N', type=str, nargs='*') | |
args = parser.parse_args() | |
if args.cols: | |
col = b','.join(args.cols) | |
else: | |
col = sys.stdin.read() | |
encoding = sys.getfilesystemencoding() | |
col = col.decode(encoding) | |
for token in separator(col): | |
print(token.encode(encoding)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment