#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    67
    Rep Power
    12

    Wink 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!
  2. #2
  3. onCsdfeu
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Canada
    Posts
    100
    Rep Power
    12
    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.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    133
    Rep Power
    12
    I think HTLCS: Learning with Python would be a good place for you to learn more.
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    67
    Rep Power
    12
    OK, I just thought that there might be a comand just for that or something.
    Thanks for your help.
  8. #5
  9. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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.
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    67
    Rep Power
    12
    Well, I don't want to repeat the whole program over and over, I just want to restart the program at a certain point.
  12. #7
  13. onCsdfeu
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Canada
    Posts
    100
    Rep Power
    12
    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.
  14. #8
  15. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    67
    Rep Power
    12
    Thats what I was looking for...
    Thanks.

IMN logo majestic logo threadwatch logo seochat tools logo