pythonwindows管道_Python使用管道(pipe)协同标准

Python使用管道(pipe)使程序通信

今天在看Python的知识时,发现了Windows下使用“|”,即管道,由于基本上没接触过因此觉得很新奇,还能通过管道配合Python的标准输入输出流来进行不同程序间的通信,传值。“|”之前的输出是“|”之后程序的输入,这点以前都没琢磨过来,只知道是这么用的,更不知道windows也行!!!

写了两个文件分别为write1.py,read1.py

write1.py:

print("Hello World!")

print(50)

read.py

print('this is my got string:%s'%input())

import sys

data = sys.stdin.readline()[:-1]

print('this data is :'+data+' double is :',int(data)*2)

调用:

D:\IStudy\Java\workspace\mypy\com\dgb\test>python write1.py | read1.py

this is my got string:Hello World!

this data is :50 double is : 100stdin is used for all interactive input (including calls toinput());

stdout is used for the output of print() and expression statements and for the prompts ofinput();

从文档的说明可以看出第一个input接收了write1的第一个print,第二个sys.stdin接收了write1.py的第二个print。

特意记录下,觉得写一些小程序时非常有用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值