python怎么重复输出_如何根据输出在Python中重复函数?

你可以用while循环来实现这一点。只要没有break或sys.exit,它就返回到start,这意味着这里的每一个错误输入。希望这有帮助def read_the_file(output):

while True:

print """

Do you want me to read your newly created file?

Type [Y]es or [N]o

"""

question = raw_input("> ")

reading = output.read()

if question == 'yes'or question == 'Y' or question == 'y':

print "BEGINNING OF FILE\n\n" + reading + "\n END OF FILE"

break # or sys.exit

elif question == 'no' or question == 'N' or question == 'n':

sys.exit[1]

else :

print "wrong input"

read_the_file(output_file)

但我建议你把代码改一下。现在,无论你想不想,每次文件被读取时。你可以在用户说“是”后再这样做。如果使用with语句,则文件将只为以下未指定部分打开。文件在这里被读取。def read_the_file(output):

while True:

print """

Do you want me to read your newly created file?

Type [Y]es or [N]o

"""

question = raw_input("> ")

if question == 'yes'or question == 'Y' or question == 'y':

# Open and read file here

with open(output, 'r') as f:

reading = f.read()

# File is now closed

print "BEGINNING OF FILE\n\n" + reading + "\n END OF FILE"

break # or sys.exit

elif question == 'no' or question == 'N' or question == 'n':

sys.exit[1]

else :

print "wrong input"

read_the_file(output_file)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值