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

[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

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")

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)

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 job

[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

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

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 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

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: try: ... 1/0 ...

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 alan.ga...@btinternet.com wrote: bob gailer bgai...@gmail.com 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

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 alan.ga...@btinternet.com wrote: bob gailer bgai...@gmail.com 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

Re: [Tutor] Exception Handling

2008-12-30 Thread Jervis Whitley
On Wed, Dec 31, 2008 at 8:33 AM, David da...@abbottdavid.com wrote: On Mon, 29 Dec 2008 16:57:44 +0100, spir wrote: On Mon, 29 Dec 2008 09:10:45 - Alan Gauld alan.ga...@btinternet.com wrote: bob gailer bgai...@gmail.com wrote Also IMHO it is bad design to put a lot of code

Re: [Tutor] Exception Handling

2008-12-30 Thread Kent Johnson
On Tue, Dec 30, 2008 at 4:33 PM, David da...@abbottdavid.com 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())) -

Re: [Tutor] Exception Handling

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

Re: [Tutor] Exception Handling

2008-12-30 Thread Jervis Whitley
On Wed, Dec 31, 2008 at 11:18 AM, David da...@abbottdavid.com 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

Re: [Tutor] Exception Handling

2008-12-29 Thread Alan Gauld
David da...@abbottdavid.com 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

Re: [Tutor] Exception Handling

2008-12-29 Thread Alan Gauld
bob gailer bgai...@gmail.com 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

Re: [Tutor] Exception Handling

2008-12-29 Thread spir
On Mon, 29 Dec 2008 09:10:45 - Alan Gauld alan.ga...@btinternet.com wrote: bob gailer bgai...@gmail.com 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!

Re: [Tutor] Exception Handling

2008-12-29 Thread Alan Gauld
spir denis.s...@free.fr 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:

[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

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

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

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 ZIYAD A. M. AL-BATLY
On Sun, 2005-09-25 at 19:44 +0530, Krishna wrote: snip 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