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)
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())
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
> 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
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
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
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("
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
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."
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:
>
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
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
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
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
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
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()
> 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 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
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
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
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
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
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
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
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
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
> 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
[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
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.
_
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
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
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
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
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
>
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
"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
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
"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
>
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
"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
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
"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
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
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
"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
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)
"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()
>
>
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
"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
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
50 matches
Mail list logo