August 25th, 2003, 12:12 PM
Newbie Question? :)
I looked around at the help files and stuff, but I coulded seem to find the code for restarting the program from the beginning. This is probally really simple...
Before you criticize someone, walk a mile in their shoes, that way when you do criticize them, you're a mile away and you have their shoes!
August 25th, 2003, 03:00 PM
Well that's kinda vague for a question.
Simple solution, you could try to put the program into a loop. like putting it inside a while 1: loop, making it an infinite loop (although you'll need a way to stop the process, then).Concretely, you could put your program in a file and get a second file like this:
say you have your main program called "moo.py" with the cow() function (main function) . Then the second could look like :
Hope this is what you were looking for.
if raw_input('Run program again ? (Y/N)') == 'N':
August 25th, 2003, 06:28 PM
August 25th, 2003, 08:46 PM
OK, I just thought that there might be a comand just for that or something.
Thanks for your help.
August 25th, 2003, 09:59 PM
Solars way was probably the most practical, you could do it using system command's i'm sure but the loop is more Pythonic and cross platform.. Why exactly do you want to repeat a whole program over and over? Isn't this why we have functions and classes?
August 26th, 2003, 02:33 PM
Well, I don't want to repeat the whole program over and over, I just want to restart the program at a certain point.
August 26th, 2003, 03:21 PM
Ok, now if I understand what you really want, you're asking for the continue keyword. I suppose you're familiar with the break statement, which stops and then exits a loop : continue stops it but does not exit the loop. It just starts anew. So you just have to add something like:
Hope that was of help.
if SomeConditionYouDecide: continue
else: #put rest of program here
August 26th, 2003, 03:37 PM
Thats what I was looking for...