美文网首页
python cook

python cook

作者: onbug | 来源:发表于2017-08-10 19:04 被阅读0次

    from itertools import dropwhile
    with open('/etc/passwd') as f:
    ... for line in dropwhile(lambda line: line.startswith('#'), f):
    ... print(line, end='')

    from itertools import chain
    >>> a = [1, 2, 3, 4]
    >>> b = ['x', 'y', 'z']
    >>> for x in chain(a, b):
    ... print(x)

    from functools import partial
    RECORD_SIZE = 32
    with open('somefile.data', 'rb') as f:
    records = iter(partial(f.read, RECORD_SIZE), b'')
    for r in records:
    ...

    相关文章

      网友评论

          本文标题:python cook

          本文链接:https://www.haomeiwen.com/subject/fxqkrxtx.html