Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
571 views
in Technique[技术] by (71.8m points)

Python Continue the loop from start when the condition is false

This is the continuation of my previous question where it was not that clear what I want to do. Now please find the Full code here I know this code is very crude as I am new to programming . I am sure this code can be written in another way more optimally but I am not that experienced. Now my question is I will be running this code from Python shell.

while 1 ==1:
    execfile('adhocTest.py')

This code consists of two parts 1. Prerequisite 2. Main program.

The prerequisite is to copy a template Excel file and paste in a directory. Main program is to do some operation and result should be written onto this file and validate few cells. If the condition is true main program will keep continuing else I want that whole script should run again i.e Run pre requisite as well as main program. I am stuc at this point as of now if teh condition is false it exits the whole script.

As I said this code is crude if anyone helps me to optimize it I will be very happy. But this is secondary. I need the continuous run of this script when the condition is false.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to re-structure your program:

def call_me():
    while True:
        prerequisite()
        main_operations()
        if validate():
            main_continuing()

or

def call_me():
    while True:
        prerequisite()
        while validation():
            main_operations()

This will loop around as you need it to.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...