iswbm / magic-python

Python 黑魔法手册
http://magic.iswbm.com/
3.32k stars 478 forks source link

5.6 中的简化臃肿代码可以使用海象运算符 #12

Closed Wang-Yaowu closed 3 years ago

Wang-Yaowu commented 3 years ago
def read_from_file(filename: str, block_size: int = 1024 * 8) -> iter:
    with open(filename, "r") as fp:
        while chunk := fp.read(block_size):
            yield chunk

使用 Python3.8 中的海象运算符可以使函数更加易读。

iswbm commented 3 years ago

感谢感谢,已更新