在迭代器被拉下流时捕获数据。

stream_tap的Python项目详细描述


流式水龙头

在迭代器被拉下流时捕获数据。

示例

#!/usr/bin/env python
# -*- coding: utf-8 -*-


from stream_tap import Bucket
from stream_tap import stream_tap


def get_fruit(item):
    """Get things that are fruit.

    :returns: thing of item if it's a fruit"""
    if len(item) == 2 and item[1] == u"fruit":
        return item[0]


def get_metal(item):
    """Get things that are metal.

    :returns: thing of item if it's metal"""
    if len(item) == 2 and item[1] == u"metal":
        return item[0]


def certain_kind_tap(data_items):
    """
    :param data_items: A sequence of unicode strings
    """
    fruit_spigot = Bucket(get_fruit)
    metal_spigot = Bucket(get_metal)

    items = stream_tap((fruit_spigot, metal_spigot), data_items)

    # consume iterator.
    for item in items:
        print item

    return fruit_spigot.contents(), metal_spigot.contents()


def run():
    """
    Run the composition of csv_file_consumer and information tap
    with the csv files in the input directory, and collect
    the results from each file and merge them together,
    printing both kinds of results.

    """
    data_items = [
        [u"mushroom", u"fungus"],
        [u"tomato", u"fruit"],
        [u"topaz", u"mineral"],
        [u"iron", u"metal"],
        [u"dróżką", u"utf-8 sample"],
        [u"apple", u"fruit"],
        [u"cheese", u"dairy"],
        [u"peach", u"fruit"],
        [u"celery", u"vegetable"],
        [u"pear", u"fruit"],
        [u"ruby", u"mineral"],
        [u"titanium", u"metal"],
        [u"cat", u"animal"],
        [u"orange", u"fruit"],
        [u"WĄŻ", u"utf-8 sample"],
    ]

    results = certain_kind_tap(data_items)

    fruits, metals = results

    print("=== fruits ===")
    for fruit in fruits:
        print(fruit)

    print("=== metals ===")
    for metal in metals:
        print(metal)


if __name__ == "__main__":
    run()

贡献:

在这里提交任何问题:https://github.com/johnwlockwood/stream_tap/issues

development的分支发出pull请求
https://github.com/johnwlockwood/stream_tap.
documentation是用structuredtext编写的,当前使用
狮身人面像风格 列表http://sphinx-doc.org/domains.html#info-field-lists

查看关闭的pull请求,查看开发流程 对master的每个更改都是通过github上的pull请求完成的。代码审查 是受欢迎的,即使是合并的请求。请随意提问 密码。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何向第二个组合框模型项添加数组值从第一个组合框所选项获取数组名称?   使用Java与WebSphere的SSL握手错误   eclipse线程“main”Java中的第一个Java程序异常。lang.NoClassDefFoundError   java将Javafx应用作为Web应用移植的最佳方式   IDE的java右JVM文件夹   java如何在基本适配器中停止文本到语音   java If block使用substring和equals方法以假值执行   在本例中,如何在java中返回多个值?   java第二个主类在maven构建期间覆盖第一个主类   如何在java中设置运行时ArrayList的泛型类型?   java从主机读取文件