[Tutor] exceptions

2005-04-15 Thread Diana Hawksworth
Hello list,   I have been trying to trap a string entry by raising an exception.  The code follows - but the exception is never raised.  What am I doing wrong?   TIA Diana    try:        self.guess = int(self.num_ent.get())       self.num_ent.delete(0,END)   

Re: [Tutor] exceptions

2005-04-15 Thread Brian van den Broek
Diana Hawksworth said unto the world upon 2005-04-15 22:25: Hello list, I have been trying to trap a string entry by raising an exception. The code follows - but the exception is never raised. What am I doing wrong? TIA Diana try: self.guess = int(self.num_ent.get())

[Tutor] exceptions problem

2010-09-10 Thread Roelof Wobben
Hello, I have this problem : Write a function named readposint that prompts the user for a positive integer and then checks the input to confirm that it meets the requirements. A sample session might look like this: >>> num = readposint() Please enter a positive integer: yes yes is not

[Tutor] exceptions problem

2010-09-11 Thread Roelof Wobben
> From: rwob...@hotmail.com > To: bgai...@gmail.com > Subject: RE: [Tutor] exceptions problem > Date: Sat, 11 Sep 2010 18:51:12 + > > > > > >> Date: Sat, 11 Sep 2010 14:43:28

Re: [Tutor] exceptions problem

2010-09-10 Thread Dave Angel
On 2:59 PM, Roelof Wobben wrote: Now I thought this would work:def readposint(): x = raw_input("Please enter a positive integer :") try: x = int(x) and x> 0 except: print x , "is not a positive integer. Try again." return False return Truey = rea

Re: [Tutor] exceptions problem

2010-09-10 Thread Francesco Loffredo
Oops, I sent this to Roelof... Ok, I must amend it anyway... On 10/09/2010 17.13, Roelof Wobben wrote: ... def readposint(): x = raw_input("Please enter a positive integer :") try: x = int(x) and x> 0 except: print x , "is not a positive i

Re: [Tutor] exceptions problem

2010-09-10 Thread Roelof Wobben
Date: Fri, 10 Sep 2010 18:07:13 +0200 From: f...@libero.it To: tutor@python.org Subject: Re: [Tutor] exceptions problem Oops, I sent this to Roelof... Ok, I must amend it anyway... On 10/09/2010 17.13, Roelof Wobben wrote: > ... > def readposint(): > x = raw_input("

Re: [Tutor] exceptions problem

2010-09-10 Thread Roelof Wobben
From: rwob...@hotmail.com To: tutor@python.org Date: Fri, 10 Sep 2010 16:12:08 + Subject: Re: [Tutor] exceptions problem Date: Fri, 10 Sep 2010 18:07:13 +0200 From: f...@libero.it To: tutor@python.org Subject: Re: [Tutor] exceptions problem Oops, I sent this to Roelof... Ok, I

Re: [Tutor] exceptions problem

2010-09-10 Thread Francesco Loffredo
On 10/09/2010 18.12, Roelof Wobben wrote: ... def readposint(): x = raw_input("Please enter a positive integer :") try: if not (x == int(x) and x< 0): raise(ValueError) except: print x , "is not a positive integer.Try again."

Re: [Tutor] exceptions problem

2010-09-10 Thread Roelof Wobben
Date: Fri, 10 Sep 2010 20:23:09 +0200 From: f...@libero.it To: tutor@python.org Subject: Re: [Tutor] exceptions problem On 10/09/2010 18.12, Roelof Wobben wrote: > ... > def readposint(): > x = raw_input("Please enter a positive integer :") > try: >

Re: [Tutor] exceptions problem

2010-09-10 Thread bob gailer
On 9/10/2010 2:48 PM, Roelof Wobben wrote: Date: Fri, 10 Sep 2010 20:23:09 +0200 From: f...@libero.it To: tutor@python.org Subject: Re: [Tutor] exceptions problem On 10/09/2010 18.12, Roelof Wobben wrote: > ... > def readposint(): > x = raw_input("Please enter a po

Re: [Tutor] exceptions problem

2010-09-10 Thread Luke Paireepinart
Sep 2010 20:23:09 +0200 > From: f...@libero.it > To: tutor@python.org > Subject: Re: [Tutor] exceptions problem > > On 10/09/2010 18.12, Roelof Wobben wrote: >> ... >> def readposint(): >> x = raw_input("Please enter a positive integer :") &g

Re: [Tutor] exceptions problem

2010-09-11 Thread Francesco Loffredo
On 11/09/2010 1.56, bob gailer wrote: On 9/10/2010 2:48 PM, Roelof Wobben wrote: Date: Fri, 10 Sep 2010 20:23:09 +0200 From: f...@libero.it To: tutor@python.org Subject: Re: [Tutor] exceptions problem ... > ... > Roelof Francesco Thank you. I never thought that you can use a float

Re: [Tutor] exceptions problem

2010-09-11 Thread Steven D'Aprano
On Sat, 11 Sep 2010 09:56:41 am bob gailer wrote: > > I never thought that you can use a float and a integer to look if > > the number is a integer. > > You can't. What? Of course you can. def is_integer(x): """Return True if x is an integer.""" try: return 1.0*x == int(x) exc

Re: [Tutor] exceptions problem

2010-09-11 Thread Peter Otten
Steven D'Aprano wrote: > On Sat, 11 Sep 2010 09:56:41 am bob gailer wrote: >> > I never thought that you can use a float and a integer to look if >> > the number is a integer. >> >> You can't. > > What? Of course you can. > > def is_integer(x): > """Return True if x is an integer.""" > t

Re: [Tutor] exceptions problem

2010-09-11 Thread bob gailer
On 9/11/2010 6:56 AM, Peter Otten wrote: Steven D'Aprano wrote: On Sat, 11 Sep 2010 09:56:41 am bob gailer wrote: I never thought that you can use a float and a integer to look if the number is a integer. You can't. I made that comment in the context of the OPs function: def readposint()

Re: [Tutor] exceptions problem

2010-09-11 Thread Roelof Wobben
> Date: Sat, 11 Sep 2010 11:05:54 -0400 > From: bgai...@gmail.com > To: tutor@python.org > Subject: Re: [Tutor] exceptions problem > > On 9/11/2010 6:56 AM, Peter Otten wrote: >> Steven D'Aprano wrote: >> >>>

Re: [Tutor] exceptions problem

2010-09-11 Thread Dave Angel
On 2:59 PM, Roelof Wobben wrote: Hello Bob, Oke, I try to fish. When I do x="a" y=nt(x) Then I get ValueError. When I do x= 1.2 y=int(x) No exception is raised. But when I do then x = I get a false. When I now do float(x) - int(x) I get 1.2 - 1 =.2 and that's greater then 0 Because one

Re: [Tutor] exceptions problem

2010-09-11 Thread bob gailer
On 9/11/2010 12:12 PM, Roelof Wobben wrote: Date: Sat, 11 Sep 2010 11:05:54 -0400 From: bgai...@gmail.com To: tutor@python.org Subject: Re: [Tutor] exceptions problem On 9/11/2010 6:56 AM, Peter Otten wrote: Steven D'Aprano wrote: On Sat, 1

Re: [Tutor] exceptions problem

2010-09-13 Thread Francesco Loffredo
On 11/09/2010 20.43, bob gailer wrote: On 9/11/2010 12:12 PM, Roelof Wobben wrote: ... You can't. I made that comment in the context of the OPs function: def readposint(): x = raw_input("Please enter a positive integer :") try: if (int(x)<0 or (float(x) - int(x)> 0)): raise(ValueError) except

Re: [Tutor] exceptions problem

2010-09-13 Thread Steven D'Aprano
On Mon, 13 Sep 2010 08:55:46 pm Francesco Loffredo wrote: > I don't like this rough behaviour of int(), spitting out an > exception if given a legitimate string representation of a float. Can > some of you Tutors explain me why it must be so? The int() function behaves as a constructor, producing

Re: [Tutor] exceptions problem

2010-09-13 Thread Francesco Loffredo
First, *THANK YOU!* for your clear and thorough explaination, Steven. On 13/09/2010 13.59, Steven D'Aprano wrote: On Mon, 13 Sep 2010 08:55:46 pm Francesco Loffredo wrote: I don't like this rough behaviour of int(), spitting out an exception if given a legitimate string representation of a floa

[Tutor] Exceptions vs. Status Codes

2005-12-06 Thread wkranec
Hi, I have a general question regarding programming style which may or may not have an answer. Is it a better practice to have a function raise an exception on error, so that the error can be caught; or return a status code indicating that the function was unsuccessful? Like I said, I don't expe

[Tutor] Exceptions for checking root, files

2005-05-21 Thread Jonas Melian
Hi, I never haven't worked with exceptions, and I'm a little confused. In my programs I always build a function to check things as: - The user that runned the script is root - All the files and directories with whom I am going to work exist - etc else the program exits. Does this checks can be

[Tutor] Exceptions and its error messages

2005-05-25 Thread Jonas Melian
Hi, How to know all the exceptions that there are? (i.e. OSError, ImportError) And all error messages of each exception? (i.e. err_o.strerror, err_o.filename) Thanks in advance! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/list

[Tutor] Exceptions while dealing with MySQL

2007-04-21 Thread Thanos Panousis
Hello list, I am developing a network management system that relies heavily on a MySQL database. The logic of the program is unavoidably coupled with query results I get from various tables. This is OK as long the mysql server has 100% uptime, but it hardly does. Say that I have to make at least

Re: [Tutor] Exceptions vs. Status Codes

2005-12-07 Thread Alan Gauld
> not have an answer. Is it a better practice to have a function raise > an exception on error, so that the error can be caught; or return a > status code indicating that the function was unsuccessful? Exceptions are nearly always better. For some of the reasons why, see my tutorial topic on Erro

Re: [Tutor] Exceptions vs. Status Codes

2005-12-07 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > Hi, > > I have a general question regarding programming style which may or may > not have an answer. Is it a better practice to have a function raise > an exception on error, so that the error can be caught; or return a > status code indicating that the function was uns

Re: [Tutor] Exceptions and its error messages

2005-05-25 Thread jfouhy
Quoting Jonas Melian <[EMAIL PROTECTED]>: > How to know all the exceptions that there are? (i.e. OSError, > ImportError) Check the Python library reference (on python.org); section 2.4: Built-in exceptions. Of course, you can subclass Exception to build your own! -- John. _

Re: [Tutor] Exceptions and its error messages

2005-05-25 Thread Kent Johnson
Jonas Melian wrote: > How to know all the exceptions that there are? (i.e. OSError, ImportError) The built-in exceptions are documented here: http://docs.python.org/lib/module-exceptions.html Some library modules define their own exceptions such as socket.error so the above is not a complete li

Re: [Tutor] Exceptions and its error messages

2005-05-25 Thread Jonas Melian
Kent Johnson wrote: > Jonas Melian wrote: >> How to know all the exceptions that there are? (i.e. OSError, ImportError) > > Some library modules define their own exceptions such as socket.error so > the above is not a complete > list of exceptions defined in the standard distribution, just the one

Re: [Tutor] Exceptions and its error messages

2005-05-25 Thread Kent Johnson
Jonas Melian wrote: > I use i.e. with OSError exception the next error messages: > err_o.strerror, err_o.filename > > :: > try: > (os.listdir(x)) > except OSError, err_o: > print "Error! %s: %r" % (err_o.strerror, err_o.filename) > :: > > But how knowing all error messages from some modul

Re: [Tutor] Exceptions and its error messages

2005-08-28 Thread lumbricus
Hello! Don't know if someone wrote this already. >But how knowing all error messages from some module? >Is there any way of knowing from python interactive line? >>> for i in dir(__builtins__): >>> if i.endswith("Error"): print i HTH and Greets, J"o! -- Wir sind jetzt ein Imperium und wi

Re: [Tutor] Exceptions while dealing with MySQL

2007-04-21 Thread Kent Johnson
Thanos Panousis wrote: > Hello list, > > I am developing a network management system that relies heavily on a > MySQL database. The logic of the program is unavoidably coupled with > query results I get from various tables. > > This is OK as long the mysql server has 100% uptime, but it hardly >

Re: [Tutor] Exceptions while dealing with MySQL

2007-04-21 Thread Thanos Panousis
Well, the best thing to do is to just keep on asking until the server is up. Sending emails and other logging can be done inside whatever wrapper function. So if wrappers is a good way to go, how should I pursue this? Just making my own wrapper functions or subclassing from MySQLdb? Is it really

Re: [Tutor] Exceptions while dealing with MySQL

2007-04-21 Thread Alan Gauld
"Thanos Panousis" <[EMAIL PROTECTED]> wrote > I am developing a network management system that relies heavily on a > MySQL database. The logic of the program is unavoidably coupled with > query results I get from various tables. That's pretty unusual, it normally indicates a non OO design. > Thi

Re: [Tutor] Exceptions while dealing with MySQL

2007-04-22 Thread John Clark
Alan Gauld wrote: >"Thanos Panousis" <[EMAIL PROTECTED]> wrote > >> I am developing a network management system that relies heavily on a >> MySQL database. The logic of the program is unavoidably coupled with >> query results I get from various tables. > >That's pretty unusual, it normally indic

Re: [Tutor] Exceptions while dealing with MySQL

2007-04-22 Thread Alan Gauld
"John Clark" <[EMAIL PROTECTED]> wrote >>> MySQL database. The logic of the program is unavoidably coupled >>> with >>> query results I get from various tables. >>That's pretty unusual, it normally indicates a non OO design. > > Database persistance has always been a frustration of mine in OO >

Re: [Tutor] Exceptions while dealing with MySQL

2007-04-22 Thread Kent Johnson
John Clark wrote: > I know that there is a text book > out there called "Database Access Patterns", can anyone provide a > recommendation or a critique of the book? Are there other (better) > references I should be consulting in designing the database interaction > layer of my application? I like

Re: [Tutor] Exceptions while dealing with MySQL

2007-04-22 Thread Alan Gauld
"Kent Johnson" <[EMAIL PROTECTED]> wrote > > I like Martin Fowler's "Patterns of Enterprise Application > Architecture". I agree, except the title can be slightly misleading. Just to make it clear, the book is about application architecture for larger scale applications (not really enterprise s

Re: [Tutor] Exceptions while dealing with MySQL

2007-04-24 Thread Thanos Panousis
Thanks to everybody for the replies. I got some nice pointers. I know my design is nasty, but that is because I am learning...Putting object orientation in the mix, I have this question: I have an object, person, which is assosiated with some statistical data. Say for each person object, I need a

Re: [Tutor] Exceptions while dealing with MySQL

2007-04-24 Thread Alan Gauld
"Thanos Panousis" <[EMAIL PROTECTED]> wrote > data. Say for each person object, I need an object variable called > "hairColor". This haircolor variable has to be filled through an SQL > query, so the object must have some way to access a database cursor. > The cool thing would be that all person

Re: [Tutor] Exceptions while dealing with MySQL

2007-04-24 Thread Kent Johnson
Thanos Panousis wrote: > I have an object, person, which is assosiated with some statistical > data. Say for each person object, I need an object variable called > "hairColor". This haircolor variable has to be filled through an SQL > query, so the object must have some way to access a database cur

Re: [Tutor] Exceptions while dealing with MySQL

2007-04-24 Thread Thanos Panousis
I checked the SQLAlchemy and SQLObject projects, but they are not really relevant to what I am doing(moreover they are more than I can chew just yet:). I managed to get a class variable to hold a cursor via something like class person: cursor = MySQLdb.connect(stuff).cursor() BUT when I make

Re: [Tutor] Exceptions while dealing with MySQL

2007-04-24 Thread Alan Gauld
"Thanos Panousis" <[EMAIL PROTECTED]> wrote in > I managed to get a class variable to hold a cursor via something > like > > class person: >cursor = MySQLdb.connect(stuff).cursor() > > BUT when I make a function inside my class called myConnect, where I > do error checking and so on, I can't

[Tutor] Exceptions: Logging TB and local variables?

2007-10-09 Thread Allen Fowler
Hi, My code looks like this: for item in bigset: self.__sub1(item) self.__sub2(item) self.__sub3(item) # the subX functions, in turn, use various 3rd party modules. Now, I would like to do this: for item in bigset: try: self.__sub1(item) self.__sub2(item)

Re: [Tutor] Exceptions: Logging TB and local variables?

2007-10-10 Thread Alan Gauld
"Allen Fowler" <[EMAIL PROTECTED]> wrote > Now, I would like to do this: > > for item in bigset: > try: > self.__sub1(item) > self.__sub2(item) > self.__sub3(item) > except StandardError: > # Log error and continue to next item in set. > log_error_to_file() > >

Re: [Tutor] Exceptions: Logging TB and local variables?

2007-10-10 Thread Kalle Svensson
On 10/10/07, Alan Gauld <[EMAIL PROTECTED]> wrote: > > "Allen Fowler" <[EMAIL PROTECTED]> wrote > > > Now, I would like to do this: > > > > for item in bigset: > > try: > > self.__sub1(item) > > self.__sub2(item) > > self.__sub3(item) > > except StandardError: > > # Log error an

Re: [Tutor] Exceptions: Logging TB and local variables?

2007-10-10 Thread Alan Gauld
"Kalle Svensson" <[EMAIL PROTECTED]> wrote >> but only if the data is in scope. If it is local data within the >> raising function then bit will be gone by the time you catch >> the exception. > > Well, not entirely. If you look at the sys.exc_info() function there > is a way to get the backtrace

Re: [Tutor] Exceptions: Logging TB and local variables?

2007-10-10 Thread Kent Johnson
Allen Fowler wrote: > In the error log, I would like to record a stacktrace and various local > variables that existed in subX at the time the Exception was thrown... The stack trace is easy - add the parameter exc_info=True to the logging call, e.g. logging.error('Oops!', exc_info=True) Wh