Re: [Tutor] Exception Handling

2015-10-03 Thread Nym City via Tutor
Thank you (Cameron and Alan) for your review and feedback. This solved the issue perfectly!  Thank you. On Friday, October 2, 2015 11:49 PM, Cameron Simpson wrote: On 03Oct2015 00:51, ALAN GAULD wrote: >On 02/10/15 23:57, Nym City via Tutor wrote: >>socket.gaierror: [Errno 1100

Re: [Tutor] Exception Handling

2015-10-02 Thread Cameron Simpson
On 03Oct2015 00:51, ALAN GAULD wrote: On 02/10/15 23:57, Nym City via Tutor wrote: socket.gaierror: [Errno 11004] getaddrinfo failed ... for name in ListOfHostNames: try: ResolveHostname = socket.gethostbyname(name) print(ResolveHostname) newFile.write(ResolveHostn

Re: [Tutor] Exception Handling

2015-10-02 Thread Alan Gauld
On 02/10/15 23:57, Nym City via Tutor wrote: socket.gaierror: [Errno 11004] getaddrinfo failed ... for name in ListOfHostNames: try: ResolveHostname = socket.gethostbyname(name) print(ResolveHostname) newFile.write(ResolveHostname + "\n") print(ResolveH

[Tutor] Exception Handling

2015-10-02 Thread Nym City via Tutor
Hello, I am trying to get IP addresses for about 500 public domains but I think for some where resolution is not available - my exception handling breaks the code.  To troubleshoot, I added several Print statements to see what I was getting and it looks like my blank list is getting populated wit

Re: [Tutor] Exception Handling and Stack traces

2010-09-11 Thread Steven D'Aprano
On Sat, 11 Sep 2010 04:47:13 am Michael Powe wrote: > No problem, I am working on getting this sorted out. The > documentation seems to be written as reminder for people who already > know how this stuff works, rather than as a clear explanation for > anybody working with it. That's because the

Re: [Tutor] Exception Handling and Stack traces

2010-09-10 Thread Michael Powe
On Fri, Sep 10, 2010 at 04:42:35PM +0200, Peter Otten wrote: > Michael Powe wrote: > > On Fri, Sep 10, 2010 at 03:56:51PM +0200, Peter Otten wrote: > >> Michael Powe wrote: > >> > I can't work out how to suppress stacktrace printing when exceptions > >> > are thrown. > >> WRONG: > >> > >> >>>

Re: [Tutor] Exception Handling and Stack traces

2010-09-10 Thread Peter Otten
Michael Powe wrote: > On Fri, Sep 10, 2010 at 03:56:51PM +0200, Peter Otten wrote: >> Michael Powe wrote: >> >> > I can't work out how to suppress stacktrace printing when exceptions >> > are thrown. >> >> [snip rant] >> >> It might have been a good idea to read a tutorial like >> >> http://do

Re: [Tutor] Exception Handling and Stack traces

2010-09-10 Thread Michael Powe
On Fri, Sep 10, 2010 at 03:50:57PM +0200, Evert Rol wrote: > This is a bit of a guess, but as far as I know, you can catch exceptions like > that. > Try: > try: > data = opener.open(url) > except urllib2.URLError as msg: > print msg > sys.exit(1) > If you're using an older versio

Re: [Tutor] Exception Handling and Stack traces

2010-09-10 Thread Evert Rol
>>> I can't work out how to suppress stacktrace printing when exceptions >>> are thrown. >> >> [snip rant] >> >> It might have been a good idea to read a tutorial like >> >> http://docs.python.org/tutorial/errors.html#handling-exceptions > >> or ask before you got annoyed enough to write that r

Re: [Tutor] Exception Handling and Stack traces

2010-09-10 Thread Michael Powe
On Fri, Sep 10, 2010 at 03:56:51PM +0200, Peter Otten wrote: > Michael Powe wrote: > > > I can't work out how to suppress stacktrace printing when exceptions > > are thrown. > > [snip rant] > > It might have been a good idea to read a tutorial like > > http://docs.python.org/tutorial/errors.htm

Re: [Tutor] Exception Handling and Stack traces

2010-09-10 Thread Peter Otten
Michael Powe wrote: > I can't work out how to suppress stacktrace printing when exceptions > are thrown. [snip rant] It might have been a good idea to read a tutorial like http://docs.python.org/tutorial/errors.html#handling-exceptions or ask before you got annoyed enough to write that rant ;)

Re: [Tutor] Exception Handling and Stack traces

2010-09-10 Thread Evert Rol
> I can't work out how to suppress stacktrace printing when exceptions > are thrown. > > I want the thrown exception to pass a message on the console, just > like Java does when I catch an exception and print e.getMessage(). > > I tried some of the examples of controlling traceback through the >

[Tutor] Exception Handling and Stack traces

2010-09-10 Thread Michael Powe
Hello, I can't work out how to suppress stacktrace printing when exceptions are thrown. I want the thrown exception to pass a message on the console, just like Java does when I catch an exception and print e.getMessage(). I tried some of the examples of controlling traceback through the tracebac

Re: [Tutor] Exception Handling

2008-12-30 Thread Jervis Whitley
On Wed, Dec 31, 2008 at 11:18 AM, David wrote: > > . I still need to get it to prduce an error if the year is 0 or 2009, the > month is 0 or 13 and the day is 0 or 32. Try using the datetime module to check validity of entered data. example: >>> import datetime >>> datetime.datetime(2008, 12,

Re: [Tutor] Exception Handling

2008-12-30 Thread David
Jervis Whitley wrote: On Wed, Dec 31, 2008 at 8:33 AM, David > wrote: On Mon, 29 Dec 2008 16:57:44 +0100, spir wrote: > On Mon, 29 Dec 2008 09:10:45 - > "Alan Gauld" mailto:alan.ga...@btinternet.com>> wrote: > >

Re: [Tutor] Exception Handling

2008-12-30 Thread Kent Johnson
On Tue, Dec 30, 2008 at 4:33 PM, David wrote: > Thank you all for the tips. Next to do is to get the dates in one raw_input > with the correct format and to check for a valid year, month, and day. Here > is what I have now; >ynum = int(time.strftime("%Y", time.gmtime())) - int(yr) >

Re: [Tutor] Exception Handling

2008-12-30 Thread Jervis Whitley
On Wed, Dec 31, 2008 at 8:33 AM, David wrote: > On Mon, 29 Dec 2008 16:57:44 +0100, spir wrote: >> >> > On Mon, 29 Dec 2008 09:10:45 - >>> > "Alan Gauld" wrote: >>> > > >>> >> "bob gailer" wrote >> > >> > Also IMHO it is bad design to put a lot of code inside a try

Re: [Tutor] Exception Handling

2008-12-30 Thread David
On Mon, 29 Dec 2008 16:57:44 +0100, spir wrote: > On Mon, 29 Dec 2008 09:10:45 - > "Alan Gauld" wrote: > > >> "bob gailer" wrote >> >> > Also IMHO it is bad design to put a lot of code inside a try block. >> > In this case the user might make a mistake on day and then is forced >> > t

Re: [Tutor] Exception Handling

2008-12-30 Thread Lie Ryan
On Mon, 29 Dec 2008 16:57:44 +0100, spir wrote: > On Mon, 29 Dec 2008 09:10:45 - > "Alan Gauld" wrote: > > >> "bob gailer" wrote >> >> > Also IMHO it is bad design to put a lot of code inside a try block. >> > In this case the user might make a mistake on day and then is forced >> > to re

Re: [Tutor] Exception Handling

2008-12-29 Thread Alan Gauld
"spir" wrote I often use the else clause of try...except. This allows putting only the minimum problematic code lines inside the try block, which is good both for legibility andto avoid catching unexpected errors. The else will be executed only in case of no exception: try: problematic_inst

Re: [Tutor] Exception Handling

2008-12-29 Thread spir
On Mon, 29 Dec 2008 09:10:45 - "Alan Gauld" wrote: > > "bob gailer" wrote > > > Also IMHO it is bad design to put a lot of code inside a try block. > > In this case the user might make a mistake on day and then is forced > > to reenter the year and month! > > Obviously there is no absol

Re: [Tutor] Exception Handling

2008-12-29 Thread Alan Gauld
"bob gailer" wrote Also IMHO it is bad design to put a lot of code inside a try block. In this case the user might make a mistake on day and then is forced to reenter the year and month! Obviously there is no absolute rule here but I disagree. One of the biggest advantages of try/except err

Re: [Tutor] Exception Handling

2008-12-29 Thread Alan Gauld
"David" wrote Is this the correct way to handle a ValueError exception and should I get in the practice of catching them? Yes and Yes. Although I woulfd move the except clause up to just after the input section (which is where the errors will be raised). A couple of other comments below:

Re: [Tutor] Exception Handling

2008-12-28 Thread bob gailer
David wrote: David wrote: Hi, Is this the correct way to handle a ValueError exception and should I get in the practice of catching them? Well yes and no. I think it is better to use the string method isdigit to test for digits only. Also IMHO it is bad design to put a lot of code inside

Re: [Tutor] Exception Handling

2008-12-28 Thread David
David wrote: Hi, Is this the correct way to handle a ValueError exception and should I get in the practice of catching them? Also any suggestions on the program. thanks -david Might help if I included the program :) #!/usr/bin/python import time print "Enter year as " print "Enter month

[Tutor] Exception Handling

2008-12-28 Thread David
Hi, Is this the correct way to handle a ValueError exception and should I get in the practice of catching them? Also any suggestions on the program. thanks -david -- Powered by Gentoo GNU/LINUX http://www.linuxcrazy.com pgp.mit.edu ___ Tutor maillist

Re: [Tutor] Exception handling - syntaxerror?!

2005-09-26 Thread Andrei
Krishna wrote: > When I have this piece of code in a function, it works fine. So is > this some limitation of directly working out off the console? It is indeed valid Python (you don't have to have empty lines after try-except in a real Python program). > Seems the console supports complete code

Re: [Tutor] Exception handling - syntaxerror?!

2005-09-25 Thread Krishna
On 25/09/05, Andrei <[EMAIL PROTECTED]> wrote: > > Think the mail system screwed up the formatting! But am fairly sure > > that I have indented it correctly in the console. Try and Except are > > in the column. Any other hints? > > Yes :). Compare: > > >>> try: > ... os.system('cls') > ... excep

Re: [Tutor] Exception handling - syntaxerror?!

2005-09-25 Thread Andrei
> Think the mail system screwed up the formatting! But am fairly sure > that I have indented it correctly in the console. Try and Except are > in the column. Any other hints? Yes :). Compare: >>> try: ... os.system('cls') ... except: ... print "Foo" ... Foo >>> print "Bar" Bar With (what y

Re: [Tutor] Exception handling - syntaxerror?!

2005-09-25 Thread ZIYAD A. M. AL-BATLY
On Sun, 2005-09-25 at 19:44 +0530, Krishna wrote: > Think the mail system screwed up the formatting! But am fairly sure > that I have indented it correctly in the console. Try and Except are > in the column. Any other hints? Make sure you're not mixing "tabs" and "spaces". A lot of editors uses

Re: [Tutor] Exception handling - syntaxerror?!

2005-09-25 Thread Krishna
On 25/09/05, ZIYAD A. M. AL-BATLY <[EMAIL PROTECTED]> wrote: > On Sun, 2005-09-25 at 18:55 +0530, Krishna wrote: > > When I try to run the following piece of code, I get a SyntaxError, > > can someone help me out on this? > > > > try: > > ... os.system("cls") > > ... except: > > ... print "Foo"

Re: [Tutor] Exception handling - syntaxerror?!

2005-09-25 Thread ZIYAD A. M. AL-BATLY
On Sun, 2005-09-25 at 18:55 +0530, Krishna wrote: > When I try to run the following piece of code, I get a SyntaxError, > can someone help me out on this? > > try: > ... os.system("cls") > ... except: > ... print "Foo" > ... print "Bar" > Traceback ( File "", line 5 > print "Bar" >

[Tutor] Exception handling - syntaxerror?!

2005-09-25 Thread Krishna
When I try to run the following piece of code, I get a SyntaxError, can someone help me out on this? try: ... os.system("cls") ... except: ... print "Foo" ... print "Bar" Traceback ( File "", line 5 print "Bar" ^ SyntaxError: invalid syntax What am I missing? Thanks in advan