Created
November 19, 2018 07:12
-
-
Save inakagawa/ca63799048fa0a3a4ffe5f89d5c7bbe6 to your computer and use it in GitHub Desktop.
This file contains 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
import re | |
import select | |
import sys | |
def isPipe(): | |
if select.select([sys.stdin,],[],[],0.0)[0]: | |
return True | |
return False | |
def get_source(): | |
if (isPipe()): | |
source = sys.stdin.read() | |
return source | |
else: | |
return "nop" | |
chunk = get_source() | |
lines = chunk.split("\n") | |
pat = re.compile("^\d{1,4}$") | |
idxbuff = "" | |
for line in lines: | |
if line =="": | |
continue | |
if pat.match(line): | |
idxbuff = line | |
continue | |
# 次のline | |
# print(line) | |
outline = "\t".join([idxbuff, line]) | |
idxbuff = "" | |
print(outline) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment