最近我在学习ApacheBeam,发现了一些类似这样的python代码:
lines = p | 'read' >> ReadFromText(known_args.input)
# Count the occurrences of each word.
def count_ones(word_ones):
(word, ones) = word_ones
return (word, sum(ones))
counts = (lines
| 'split' >> (beam.ParDo(WordExtractingDoFn())
.with_output_types(unicode))
| 'pair_with_one' >> beam.Map(lambda x: (x, 1))
| 'group' >> beam.GroupByKey()
| 'count' >> beam.Map(count_ones))
发件人:https://github.com/apache/beam/blob/master/sdks/python/apache_beam/examples/wordcount.py#L92
python中|
和>>
的语法和用法是什么?你知道吗
默认情况下,} 和^{} 中重载以下两个dunder(magic)方法:
|
表示逻辑或逐位或运算符,>>
表示右移位,但幸运的是,您可以在Python中重载运算符。因此,为了拥有|
和>>,
的自定义定义,您只需在类^{我建议您阅读更多关于Python Data Model的内容。你知道吗
现在查看Beam Python SDK,
__or__
在PTransform
类中重载:相关问题 更多 >
编程相关推荐