The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Newbie Question? :)
Discuss Newbie Question? :) in the Python Programming forum on Dev Shed. Newbie Question? :) Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

August 25th, 2003, 11:12 AM
|
 |
Contributing User
|
|
Join Date: Aug 2003
Posts: 67
Time spent in forums: 41 m
Reputation Power: 10
|
|
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...
Thanks.
__________________
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, 02:00 PM
|
 |
onCsdfeu
|
|
Join Date: Jul 2003
Location: Canada
Posts: 100
Time spent in forums: 2 h 16 m 21 sec
Reputation Power: 10
|
|
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 :
Code:
import moo
while 1:
moo.cow()
if raw_input('Run program again ? (Y/N)') == 'N':
break
Hope this is what you were looking for.
|

August 25th, 2003, 05:28 PM
|
|
Contributing User
|
|
Join Date: Jul 2003
Posts: 133
Time spent in forums: < 1 sec
Reputation Power: 10
|
|
|

August 25th, 2003, 07:46 PM
|
 |
Contributing User
|
|
Join Date: Aug 2003
Posts: 67
Time spent in forums: 41 m
Reputation Power: 10
|
|
|
OK, I just thought that there might be a comand just for that or something.
Thanks for your help.
|

August 25th, 2003, 08:59 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
|
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?
have fun,
Mark.
|

August 26th, 2003, 01:33 PM
|
 |
Contributing User
|
|
Join Date: Aug 2003
Posts: 67
Time spent in forums: 41 m
Reputation Power: 10
|
|
|
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, 02:21 PM
|
 |
onCsdfeu
|
|
Join Date: Jul 2003
Location: Canada
Posts: 100
Time spent in forums: 2 h 16 m 21 sec
Reputation Power: 10
|
|
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:
Code:
if SomeConditionYouDecide: continue
else: #put rest of program here
Hope that was of help.
|

August 26th, 2003, 02:37 PM
|
 |
Contributing User
|
|
Join Date: Aug 2003
Posts: 67
Time spent in forums: 41 m
Reputation Power: 10
|
|
|
Thats what I was looking for...
Thanks.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|