这是一个创建于 4419 天前的主题,其中的信息可能已经有所发展或是发生改变。
大家早上好,问题是这样的:
修改前是三个函数:
funA()
funB()
funC()
其中
def funC():
...#若干嵌套
if X:
cry_out
if Y:
do_sth
现在想要改成:funA、funB、funC一路跑下来,第一次遇到if X为True的时候不执行cry_out,而是倒回去把funA、funB、funC再跑一遍,再次遇到if X为True再cry_out,当然if X为False的行为不变。
我有很多笨办法比如设flag之类但自己感觉不好,所以想求教一下各位高手怎么改比较漂亮?
3 条回复 • 1970-01-01 08:00:00 +08:00
|
|
1
lilydjwg 2012-08-15 09:08:39 +08:00 1
这样? rerun = False while True: funA() funB() if not funC(rerun): break
def funC(rerun): #... if X and not rerun: return True if X: cry_out
|
|
|
2
lilydjwg 2012-08-15 09:09:37 +08:00
囧,忘记置位 rerun 了…… 另外,缩进没了怎么办?
|
|
|
3
ThunderEX 2012-08-15 10:44:09 +08:00
@ lilydjwg 我差不多也是这样想的,就是觉得既改动definition又改动reference不太雅观。还是谢谢~
|