本文整理匯總了Python中sys.stdin.readline方法的典型用法代碼示例。如果您正苦於以下問題:Python stdin.readline方法的具體用法?Python stdin.readline怎麽用?Python stdin.readline使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sys.stdin
的用法示例。
在下文中一共展示了stdin.readline方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: handle
# 需要導入模塊: from sys import stdin [as 別名]
# 或者: from sys.stdin import readline [as 別名]
def handle(self):
print_flush("New connection: {}".format(self.client_address))
while True:
msg = self.rfile.readline()
if not msg:
break
msg = msg.strip()
print_flush((msg[:74] + '...') if len(msg) > 74 else msg, end='')
options = {
'kill': self.server.matlab.kill,
'cancel': self.server.matlab.cancel,
}
if msg in options:
options[msg]()
else:
self.server.matlab.run_code(msg)
print_flush('Connection closed: {}'.format(self.client_address))
示例2: readcase
# 需要導入模塊: from sys import stdin [as 別名]
# 或者: from sys.stdin import readline [as 別名]
def readcase():
nshuffles = int(stdin.readline())
# Read all shuffles into a single list and then split them, because
# a shuffle could extend more than one line
all_shuffles = []
while len(all_shuffles)<nshuffles*52:
all_shuffles.extend(readnum())
shuffles = []
for i in range(nshuffles):
shuffles.append(all_shuffles[i*52:(i+1)*52])
# Read shuffles observed
observed = []
while True:
try:
seen = int(stdin.readline())
observed.append(seen)
except Exception:
break #Found empty line
return shuffles, observed
示例3: loadcase
# 需要導入模塊: from sys import stdin [as 別名]
# 或者: from sys.stdin import readline [as 別名]
def loadcase():
# Discard empty line
_ = stdin.readline()
# Ferry length in cm
length = int(stdin.readline())*100
# Read car dimmensions until 0 is reached
cars = []
car = int(stdin.readline())
while car>0:
cars.append(car)
car = int(stdin.readline())
return length, cars
示例4: forward_input
# 需要導入模塊: from sys import stdin [as 別名]
# 或者: from sys.stdin import readline [as 別名]
def forward_input(matlab):
"""Forward stdin to Matlab.proc's stdin."""
if use_pexpect:
matlab.proc.interact(input_filter=input_filter,output_filter=output_filter)
else:
while True:
matlab.proc.stdin.write(stdin.readline())
示例5: readcase
# 需要導入模塊: from sys import stdin [as 別名]
# 或者: from sys.stdin import readline [as 別名]
def readcase():
fragments = []
while True:
frag = stdin.readline().strip()
if len(frag) == 0:
break
fragments.append(frag)
return list(map(list, fragments))
示例6: readnum
# 需要導入模塊: from sys import stdin [as 別名]
# 或者: from sys.stdin import readline [as 別名]
def readnum():
return list(map(int, stdin.readline().split()))
示例7: readnum
# 需要導入模塊: from sys import stdin [as 別名]
# 或者: from sys.stdin import readline [as 別名]
def readnum():
line = stdin.readline()
if not line:
return None, None
return [int(x) for x in line.split()]
示例8: readdict
# 需要導入模塊: from sys import stdin [as 別名]
# 或者: from sys.stdin import readline [as 別名]
def readdict():
d = set()
while True:
word = stdin.readline().strip()
if len(word) == 0:
break
d.add(word)
return d
示例9: readwords
# 需要導入模塊: from sys import stdin [as 別名]
# 或者: from sys.stdin import readline [as 別名]
def readwords():
cases = []
while True:
case = tuple(stdin.readline().split())
if not case:
break
cases.append(case)
return cases
示例10: readnum
# 需要導入模塊: from sys import stdin [as 別名]
# 或者: from sys.stdin import readline [as 別名]
def readnum():
return int(stdin.readline())
示例11: readstick
# 需要導入模塊: from sys import stdin [as 別名]
# 或者: from sys.stdin import readline [as 別名]
def readstick():
"""Read one stick problem form stdin"""
length = int(stdin.readline())
if not length:
return None, None
ncuts = int(stdin.readline())
cuts = list(map(int, stdin.readline().split()))
return length, cuts
示例12: readhand
# 需要導入模塊: from sys import stdin [as 別名]
# 或者: from sys.stdin import readline [as 別名]
def readhand():
"""Read next hand into back a white hands"""
both_hands = stdin.readline().split()
if not both_hands:
return None, None
both_hands = [Card(v, s) for v, s in both_hands]
black_hand, white_hand = both_hands[:5], both_hands[5:]
return black_hand, white_hand
示例13: load_num
# 需要導入模塊: from sys import stdin [as 別名]
# 或者: from sys.stdin import readline [as 別名]
def load_num():
return int(stdin.readline())
示例14: load_pair
# 需要導入模塊: from sys import stdin [as 別名]
# 或者: from sys.stdin import readline [as 別名]
def load_pair():
return tuple(map(int, stdin.readline().split()))
示例15: run
# 需要導入模塊: from sys import stdin [as 別名]
# 或者: from sys.stdin import readline [as 別名]
def run(args):
"""Install a shared-secret to this cluster.
When invoked interactively, you'll be prompted to enter the secret.
Otherwise the secret will be read from the first line of stdin.
In both cases, the secret must be hex/base16 encoded.
"""
# Obtain the secret from the invoker.
if stdin.isatty():
try:
secret_hex = input("Secret (hex/base16 encoded): ")
except EOFError:
print() # So that the shell prompt appears on the next line.
raise SystemExit(1)
except KeyboardInterrupt:
print() # So that the shell prompt appears on the next line.
raise
else:
secret_hex = stdin.readline()
# Decode and install the secret.
try:
secret = to_bin(secret_hex.strip())
except binascii.Error as error:
print("Secret could not be decoded:", str(error), file=stderr)
raise SystemExit(1)
else:
set_shared_secret_on_filesystem(secret)
shared_secret_path = get_shared_secret_filesystem_path()
print("Secret installed to %s." % shared_secret_path)
raise SystemExit(0)