看板 Python 關於我們 聯絡資訊
※ 引述《timerover (再也不會輸了!!!)》之銘言: : 請問python有類似C語言中scanf的fomat input嗎 : 我查了查 只有看到format output : 現在遇到了個問題 使用者輸入單行 "input1 input2 input3" : 用空白分隔 : input()吃不進來 : raw_input()進來parse雖可達到目的 但頗耗費時間 : 不知道有沒有好方法 : 懇請板上大大解答 我寫了一個 readSep, 每次可以取得一個用泛白字元隔開的 token 不知道這樣合不合用? def readSep(): while( True ): line = raw_input() for s in line.split(): yield s if __name__ == '__main__': r = readSep() while( True ): try: print r.next() except EOFError: break 如果只是單純想取得空白隔開的字串,那下面這樣就可以了: line = raw_input(); for s in line.split(): print s -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.31.163
timerover:非常感謝:) 11/01 22:33