Re: More elegant way to try running a function X times?

2008-11-20 Thread Boris Borcic
Tim Chase wrote: success = None for i in range(5): #Try to fetch public IP success = CheckIP() if success: break if not success: print Exiting. sys.exit() Though a bit of an abuse, you can use if not any(CheckIP() for _ in range(5)): print Exiting

Re: More elegant way to try running a function X times?

2008-11-20 Thread Tim Chase
success = None for i in range(5): #Try to fetch public IP success = CheckIP() if success: break if not success: print Exiting. sys.exit() Though a bit of an abuse, you can use if not any(CheckIP() for _ in range(5)): print Exiting sys.exit() I don't see

Re: More elegant way to try running a function X times?

2008-11-20 Thread Steve Holden
Gilles Ganault wrote: Hello As a newbie, it's pretty likely that there's a smarter way to do this, so I'd like to check with the experts: I need to try calling a function 5 times. If successful, move on; If not, print an error message, and exit the program: = success = None for

Re: More elegant way to try running a function X times?

2008-11-20 Thread Banibrata Dutta
On Thu, Nov 20, 2008 at 11:58 PM, Steve Holden [EMAIL PROTECTED] wrote: Gilles Ganault wrote: Hello As a newbie, it's pretty likely that there's a smarter way to do this, so I'd like to check with the experts: I need to try calling a function 5 times. If successful, move on; If

Re: More elegant way to try running a function X times?

2008-11-20 Thread Boris Borcic
Tim Chase wrote: success = None for i in range(5): #Try to fetch public IP success = CheckIP() if success: break if not success: print Exiting. sys.exit() Though a bit of an abuse, you can use if not any(CheckIP() for _ in range(5)): print Exiting

More elegant way to try running a function X times?

2008-11-19 Thread Gilles Ganault
Hello As a newbie, it's pretty likely that there's a smarter way to do this, so I'd like to check with the experts: I need to try calling a function 5 times. If successful, move on; If not, print an error message, and exit the program: = success = None for i in range(5): #Try to

Re: More elegant way to try running a function X times?

2008-11-19 Thread Tim Chase
I need to try calling a function 5 times. If successful, move on; If not, print an error message, and exit the program: success = None for i in range(5): #Try to fetch public IP success = CheckIP() if success: break if not success: print Exiting.

Re: More elegant way to try running a function X times?

2008-11-19 Thread Sion Arrowsmith
Gilles Ganault [EMAIL PROTECTED] wrote: As a newbie, it's pretty likely that there's a smarter way to do this, so I'd like to check with the experts: I need to try calling a function 5 times. If successful, move on; If not, print an error message, and exit the program: = success = None for

Re: More elegant way to try running a function X times?

2008-11-19 Thread Nicholas Ferenc Fabry
On Nov 19, 2008, at 09:09, Gilles Ganault wrote: Hello As a newbie, it's pretty likely that there's a smarter way to do this, so I'd like to check with the experts: I need to try calling a function 5 times. If successful, move on; If not, print an error message, and exit the program: =

Re: More elegant way to try running a function X times?

2008-11-19 Thread Gilles Ganault
On 19 Nov 2008 14:37:06 + (GMT), Sion Arrowsmith [EMAIL PROTECTED] wrote: Note very carefully that the else goes with the for and not the if. Thanks guys. -- http://mail.python.org/mailman/listinfo/python-list

Re: More elegant way to try running a function X times?

2008-11-19 Thread George Sakkis
On Nov 19, 10:21 am, Gilles Ganault [EMAIL PROTECTED] wrote: On 19 Nov 2008 14:37:06 + (GMT), Sion Arrowsmith [EMAIL PROTECTED] wrote: Note very carefully that the else goes with the for and not the if. Thanks guys. And if you end up doing this for several different functions, you can