语法糖 - Python pipe管道用法
高洛峰
高洛峰 2017-04-17 14:51:55
0
1
369

Python语法问题

描述

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

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

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

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(1)
大家讲道理

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.
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!