search

Home  >  Q&A  >  body text

语法糖 - Python pipe管道用法

Python语法问题

描述

我使用第三方的pipe管道库,来进行一些类似linux sh中管道方式运算,遇到疑惑。见如下代码:

>>> from pipe import *
>>> [1, 2, 3] | sum
>>> 6

上面这段代码,管道描述符| 在python中不是按位或的运算符吗,为这么在这里可以作为类似linux下的管道符呢?查看pipe.py源文件,没有发现重载这个运算符啊?

高洛峰高洛峰2770 days ago421

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 14:53:55

    Found it, carefully looked at the pipe.py file, and found that the class Pipe has re-added the bitwise OR operator, realizing a function similar to the pipe operator in Linux sh.

    Summary

    1. Like the scapy library, the / division operator is overloaded and used as a connection operator, so pay special attention to this type of operator overloading in the future.

    reply
    0
  • Cancelreply