Skip to content

Instantly share code, notes, and snippets.

@inakagawa
Created November 19, 2018 07:12
Show Gist options
  • Save inakagawa/ca63799048fa0a3a4ffe5f89d5c7bbe6 to your computer and use it in GitHub Desktop.
Save inakagawa/ca63799048fa0a3a4ffe5f89d5c7bbe6 to your computer and use it in GitHub Desktop.
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