当前位置: 首页>>代码示例>>Python>>正文


Python stdin.readline方法代码示例

本文整理汇总了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)) 
开发者ID:daeyun,项目名称:vim-matlab,代码行数:22,代码来源:vim-matlab-server.py

示例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 
开发者ID:secnot,项目名称:uva-onlinejudge-solutions,代码行数:25,代码来源:main.py

示例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 
开发者ID:secnot,项目名称:uva-onlinejudge-solutions,代码行数:19,代码来源:main.py

示例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()) 
开发者ID:daeyun,项目名称:vim-matlab,代码行数:9,代码来源:vim-matlab-server.py

示例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)) 
开发者ID:secnot,项目名称:uva-onlinejudge-solutions,代码行数:13,代码来源:main.py

示例6: readnum

# 需要导入模块: from sys import stdin [as 别名]
# 或者: from sys.stdin import readline [as 别名]
def readnum():
    return list(map(int, stdin.readline().split())) 
开发者ID:secnot,项目名称:uva-onlinejudge-solutions,代码行数:4,代码来源:main.py

示例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()] 
开发者ID:secnot,项目名称:uva-onlinejudge-solutions,代码行数:7,代码来源:main.py

示例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 
开发者ID:secnot,项目名称:uva-onlinejudge-solutions,代码行数:11,代码来源:main.py

示例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 
开发者ID:secnot,项目名称:uva-onlinejudge-solutions,代码行数:11,代码来源:main.py

示例10: readnum

# 需要导入模块: from sys import stdin [as 别名]
# 或者: from sys.stdin import readline [as 别名]
def readnum():
    return int(stdin.readline()) 
开发者ID:secnot,项目名称:uva-onlinejudge-solutions,代码行数:4,代码来源:main.py

示例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 
开发者ID:secnot,项目名称:uva-onlinejudge-solutions,代码行数:13,代码来源:main.py

示例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 
开发者ID:secnot,项目名称:uva-onlinejudge-solutions,代码行数:13,代码来源:main.py

示例13: load_num

# 需要导入模块: from sys import stdin [as 别名]
# 或者: from sys.stdin import readline [as 别名]
def load_num():
    return int(stdin.readline()) 
开发者ID:secnot,项目名称:uva-onlinejudge-solutions,代码行数:4,代码来源:main.py

示例14: load_pair

# 需要导入模块: from sys import stdin [as 别名]
# 或者: from sys.stdin import readline [as 别名]
def load_pair():
    return tuple(map(int, stdin.readline().split())) 
开发者ID:secnot,项目名称:uva-onlinejudge-solutions,代码行数:4,代码来源:main.py

示例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) 
开发者ID:maas,项目名称:maas,代码行数:33,代码来源:security.py


注:本文中的sys.stdin.readline方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。