python运行input不出结果_python input()使用疑问

这篇博客讨论了在Ubuntu 12.04的Python环境中,使用input()在Python3.5.1下运行失败,而使用raw_input()在Python2.7下运行成功的问题。作者提供了包含管道通信和进程间交互的代码示例,并展示了遇到的错误信息。博客主要关注Python不同版本间的输入函数差异及其在实际应用中的影响。
摘要由CSDN通过智能技术生成

请大家帮忙看看,>_<

运行环境 虚拟机 ubuntu12.04 python3.5.1

用 input() python3 运行失败

用 raw_input(), python2 运行成功

#!/usr/bin/env python3

# -*- coding: utf-8 -*-

import os

import time

p = os.pipe()

childpid = os.fork()

if (childpid==0):

os.close(p[1])

while True:

time.sleep(3)

print('reading')

msg = os.read(p[0],1024)

print(msg)

if msg == '':

print('can not read anything')

break

if (msg == 'q'):

os.close(p[0])#关闭管道

break

else:

os.close(p[0])

while True:

#python3.5 中运行出错

str1 = input()

#python2.7 中运行正确

#str1 = raw_input('input anything:')

os.write(p[1],str1)

if(str1 == 'q'):

os.close(p[1])#关闭管道

os.wait()

break

出错信息如图:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值