Source code for titan_pylib.io.fast_o

 1import os
 2import io
 3
 4
[docs] 5class FastO: 6 """標準出力高速化ライブラリです。""" 7 8 _output = io.StringIO() 9
[docs] 10 @classmethod 11 def write(cls, *args, sep: str = " ", end: str = "\n", flush: bool = False) -> None: 12 """標準出力します。次の ``FastO.flush()`` が起きると print します。""" 13 wr = cls._output.write 14 for i in range(len(args) - 1): 15 wr(str(args[i])) 16 wr(sep) 17 if args: 18 wr(str(args[-1])) 19 wr(end) 20 if flush: 21 cls.flush()
22
[docs] 23 @classmethod 24 def flush(cls) -> None: 25 """``flush`` します。これを実行しないと ``write`` した内容が表示されないので忘れないでください。""" 26 os.write(1, cls._output.getvalue().encode()) 27 cls._output.close()