473,289 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

Restarting a program

Hello all, I have written a simple program, and at the end of it,
instead of it closing I would like it to restart from the beggining.
Is there a way to do this? Put my code into a class function, or
something?
I guess I could do a while loop, but I think if there is a way to run
my code if it's in a class would be an easier option. I can't seem to
find many guides online but maybe I have not been looking in the right
places.

Anybody have any ideas?
Jun 27 '08 #1
4 1497
On May 22, 10:59*am, Geoldr <geo...@gmail.comwrote:
Hello all, I have written a simple program, and at the end of it,
instead of it closing I would like it to restart from the beggining.
Is there a way to do this? Put my code into a class function, or
something?
I guess I could do a while loop, but I think if there is a way to run
my code if it's in a class would be an easier option. I can't seem to
find many guides online but maybe I have not been looking in the right
places.

Anybody have any ideas?
Putting your code in a function or class is probably the way to go.
When I was doing C++, we'd just use a while loop for simple stuff,
though.

It really shouldn't be all that hard to tell the code to call up the
beginning of the program again.

Mike
Jun 27 '08 #2
On May 22, 10:07*am, Mike Driscoll <kyoso...@gmail.comwrote:
On May 22, 10:59*am, Geoldr <geo...@gmail.comwrote:
Hello all, I have written a simple program, and at the end of it,
instead of it closing I would like it to restart from the beggining.
Is there a way to do this? Put my code into a class function, or
something?
I guess I could do a while loop, but I think if there is a way to run
my code if it's in a class would be an easier option. I can't seem to
find many guides online but maybe I have not been looking in the right
places.
Anybody have any ideas?

Putting your code in a function or class is probably the way to go.
When I was doing C++, we'd just use a while loop for simple stuff,
though.

It really shouldn't be all that hard to tell the code to call up the
beginning of the program again.

Mike
That's what I am trying to figure out, but it doesn't seem to work. Do
you have any example code of classes/functions that work for you?
Jun 27 '08 #3
On May 22, 1:38*pm, Geoldr <geo...@gmail.comwrote:
On May 22, 10:07*am, Mike Driscoll <kyoso...@gmail.comwrote:
On May 22, 10:59*am, Geoldr <geo...@gmail.comwrote:
Hello all, I have written a simple program, and at the end of it,
instead of it closing I would like it to restart from the beggining.
Is there a way to do this? Put my code into a class function, or
something?
I guess I could do a while loop, but I think if there is a way to run
my code if it's in a class would be an easier option. I can't seem to
find many guides online but maybe I have not been looking in the right
places.
Anybody have any ideas?
Putting your code in a function or class is probably the way to go.
When I was doing C++, we'd just use a while loop for simple stuff,
though.
It really shouldn't be all that hard to tell the code to call up the
beginning of the program again.
Mike

That's what I am trying to figure out, but it doesn't seem to work. Do
you have any example code of classes/functions that work for you?
No...but I through some concept code together that does the basics:

<code>

def repeater():

for i in range(10):
print i

def main():
ret = 'Y'
while 1:
if ret.upper() == 'Y':
repeater()
else:
print 'Program finished...goodbye!'
break
ret = raw_input('Do you want to continue? (Y/N)')

if __name__ == '__main__':
main()

</code>

I found that using the while was the easiest to create on short
notice. You could probably do it with recursion too, but I'm not
especially good at that.

Another idea is to have some kind of sentinel value that both
functions can access and use it somehow to tell whether or not to
repeat.

Hope that helps you get going.

Mike
Jun 27 '08 #4
On May 22, 11:58*am, Mike Driscoll <kyoso...@gmail.comwrote:
On May 22, 1:38*pm, Geoldr <geo...@gmail.comwrote:
On May 22, 10:07*am, Mike Driscoll <kyoso...@gmail.comwrote:
On May 22, 10:59*am, Geoldr <geo...@gmail.comwrote:
Hello all, I have written a simple program, and at the end of it,
instead of it closing I would like it to restart from the beggining.
Is there a way to do this? Put my code into a class function, or
something?
I guess I could do a while loop, but I think if there is a way to run
my code if it's in a class would be an easier option. I can't seem to
find many guides online but maybe I have not been looking in the right
places.
Anybody have any ideas?
Putting your code in a function or class is probably the way to go.
When I was doing C++, we'd just use a while loop for simple stuff,
though.
It really shouldn't be all that hard to tell the code to call up the
beginning of the program again.
Mike
That's what I am trying to figure out, but it doesn't seem to work. Do
you have any example code of classes/functions that work for you?

No...but I through some concept code together that does the basics:

<code>

def repeater():

* * for i in range(10):
* * * * print i

def main():
* * ret = 'Y'
* * while 1:
* * * * if ret.upper() == 'Y':
* * * * * * repeater()
* * * * else:
* * * * * * print 'Program finished...goodbye!'
* * * * * * break
* * * * ret = raw_input('Do you want to continue? (Y/N)')

if __name__ == '__main__':
* * main()

</code>

I found that using the while was the easiest to create on short
notice. You could probably do it with recursion too, but I'm not
especially good at that.

Another idea is to have some kind of sentinel value that both
functions can access and use it somehow to tell whether or not to
repeat.

Hope that helps you get going.

Mike
Thank you, the "def" option works the best.
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Phil S | last post by:
My server is randomly restarting every few minutes or so, and I can't figure out why. What would cause this to happen, aside from some evil person sitting at the console? I did manage to catch it...
0
by: LJ | last post by:
I have been getting this message and can't resolve the problem. I have checked the AntiVirus software and added the application directory to the exculsion list. The application is on a web farm,...
4
by: Hari Koduru | last post by:
Hi All, I am getting the following exception in an ASP.NET application. Exception Details: System.InvalidOperationException: Application is restarting. I have been to the following Support...
4
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi... Following the samples online, we implemented a windows service in .Net. Like most services, there's a worker thread actually doing stuff in the background. The problem we've run into is...
3
by: gourmet | last post by:
Hello! I need to restart the "Windows Audio Service" (audiosrv) via C#. I'm using the ServiceController Class to do this. It is no problem under XP and no problem under vista if UAC is...
10
by: kyosohma | last post by:
Hi, I packaged up an application I am developing into an executable. In the application, it has user configurable options. I would like a way to restart the application so that the new options...
1
by: Adam Atlas | last post by:
What is the best way for a Python process (presumed to be a script run by the interpreter binary, not embedded in some other program) to restart itself? This is what I've been trying: import...
2
by: crusson | last post by:
I am making a program which opens textfiles, initiates a bunch of variables and opens the file for editing. I want to be able to close one text file and open another with the variables at their...
1
by: prpradip | last post by:
In my C program, sometimes I am getting error status code 41728. Using OSLoadString I get its equivalent as "Process ID has been reused, application may require restarting if OSLoadProgram was not...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.