當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。