Re: [Tutor] whats the best command to end a program
> what would be the best command to end a program with. > i have an app that i want to start every day at 6am from cron > but i want it to shutdown at 4pm > > i was going to check by time on every loop > > if int(time.strftime(%H)) > 4: > some end the program command > else: > continue > > what would be best used here ? i think using int(), strftime(), takes too much computation. what's wrong with just if time.localtime()[3] >= 16: # do cleanup # raise SystemExit or import sys;sys.exit() you don't even need the continue. hope this helps! -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2006,2001 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] whats the best command to end a program
if int(time.strftime(%H)) > 4:some end the program command else:continuewhat would be best used here ? I would use raise SystemExit But another possibility is: import sys then to exit sys.exit()-- There are 10 different types of people in the world.Those who understand binary and those who don't. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] whats the best command to end a program
right, greater > 16 was what i ment. he he it is not a gui. is raise SystemExit built in ? thanks gents sk On Tue, 2005-12-06 at 21:49 +, Alan Gauld wrote: > > what would be the best command to end a program with. > > If its Tkinter (or another GuI) there will be a quit command > somewhere. Call that to ensure that the GUI framework gets > tidied up properly. > > For normal programs > > import sys; sys.exit() > > You can pass an exit code to the outdside world as > a parameter to exit too. > > or just > > raise SystemExit > > will work. > > > i have an app that i want to start every day at 6am from cron > > but i want it to shutdown at 4pm > > OK, here you probably want system.exit(n) with a proper error > code so that cron can tell if it worked or not... > > BTW strftime('%H') returns the hour in 24 hour format so you > will want to check for 16 not 4... > > Alan G > Author of the learn to program web tutor > http://www.freenetpages.co.uk/hp/alan.gauld > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] whats the best command to end a program
> what would be the best command to end a program with. If its Tkinter (or another GuI) there will be a quit command somewhere. Call that to ensure that the GUI framework gets tidied up properly. For normal programs import sys; sys.exit() You can pass an exit code to the outdside world as a parameter to exit too. or just raise SystemExit will work. > i have an app that i want to start every day at 6am from cron > but i want it to shutdown at 4pm OK, here you probably want system.exit(n) with a proper error code so that cron can tell if it worked or not... BTW strftime('%H') returns the hour in 24 hour format so you will want to check for 16 not 4... Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor