Skip to content

Instantly share code, notes, and snippets.

@yuitest
Created March 26, 2014 18:41
Show Gist options
  • Save yuitest/9790289 to your computer and use it in GitHub Desktop.
Save yuitest/9790289 to your computer and use it in GitHub Desktop.
引数やら標準入力やらで入ってきた文字を、テキトーにちょんぎって、改行して出力する。
#!/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