Carl Banks <[EMAIL PROTECTED]> wrote:
> Perhaps the advent of with blocks will help reduce this error in the
> future.
Indeed, and to encourage its use I think this thread ought to include the
'with statement' form of the function:
from __future__ import with_statement
from contextlib import cl
On Apr 2, 9:06 am, [EMAIL PROTECTED] wrote:
> Hi,
>
> I found the following code on the net -
>
> http://mail-archives.apache.org/mod_mbox/httpd-python-cvs/200509.mbox/[EMAIL
> PROTECTED]
>
> def count(self):
> -db = sqlite.connect(self.filename,
> isolation_level=ISOLATION_LEVEL)
> -
cur
> > > > = db.cursor(). Can anyone explain for me why?
>
> > > > /Barry.
>
> > > Better question is why is there a try with no except...
>
> > > Better yet, WHY is there two TRY statements when there could quite
> > > happily be only on
On 2 avr, 15:12, [EMAIL PROTECTED] wrote:
> On Apr 2, 3:06 pm, [EMAIL PROTECTED] wrote:
>
>
>
> > Hi,
>
> > I found the following code on the net -
>
> > http://mail-archives.apache.org/mod_mbox/httpd-python-cvs/200509.mbox/[EMAIL
> > PROTECTED]
>
> > def count(self):
> > -db = sqlite.
> > Better question is why is there a try with no except...
>
> > > > Better yet, WHY is there two TRY statements when there could quite
> > > > happily be only one...
>
> > > > Towards what you are asking, I GUESS...because the author hoped t
line cur
> > > > = db.cursor(). Can anyone explain for me why?
>
> > > > /Barry.
>
> > > Better question is why is there a try with no except...
>
> > > Better yet, WHY is there two TRY statements when there could quite
> > > happily b
with no except...
>
> > Better yet, WHY is there two TRY statements when there could quite
> > happily be only one...
>
> > Towards what you are asking, I GUESS...because the author hoped to
> > handle the cases where cur failed to get assigned...but then
> > his
king, I GUESS...because the author hoped to
> handle the cases where cur failed to get assigned...but then
> his .close method of it would likely not work anyway...I mean...does
> this even work...YUCK
I shouldn't have written "Nested try...except" as the title,
[EMAIL PROTECTED] wrote:
> Hi,
>
> I found the following code on the net -
>
> http://mail-archives.apache.org/mod_mbox/httpd-python-cvs/200509.mbox/%
> [EMAIL PROTECTED]
>
> def count(self):
> -db = sqlite.connect(self.filename,
> isolation_level=ISOLATION_LEVEL)
> -tr
On Apr 2, 3:06 pm, [EMAIL PROTECTED] wrote:
> Hi,
>
> I found the following code on the net -
>
> http://mail-archives.apache.org/mod_mbox/httpd-python-cvs/200509.mbox/[EMAIL
> PROTECTED]
>
> def count(self):
> -db = sqlite.connect(self.filename,
> isolation_level=ISOLATION_LEVEL)
> -
Hi,
I found the following code on the net -
http://mail-archives.apache.org/mod_mbox/httpd-python-cvs/200509.mbox/[EMAIL
PROTECTED]
def count(self):
-db = sqlite.connect(self.filename,
isolation_level=ISOLATION_LEVEL)
-try:
-try:
-cur
Simon Forman wrote:
> I'm sorry to hear that. I thought it was cleaner and more
> understandable than that. May I indulge in explaining it a bit? I
> can, perhaps, make it clearer.
Thanks for the explanation. I find that with a little concentration,
it's not that it's hard to follow the code,
Boris Borcic wrote:
> Boris Borcic wrote:
>> John Salerno wrote:
>>> In this case the method must return False, because it's a wxPython
>>> method that needs a True or False value. If it doesn't, the program
>>> will continue even after the error message.
>>
>> Just as it should do if the method
On Thu, 10 Aug 2006 16:42:47 -0700
Simon Forman <[EMAIL PROTECTED]> wrote:
#> 6.) There's a single return statement.
#>
#> I forget now where I picked this up, but it's served me well for
#> many years: Procedures, functions, methods, etc... should have one
#> exit point. Something about having f
John Salerno wrote:
> Simon Forman wrote:
>
> > What about the version I gave you 8 days ago? ;-)
> >
> > http://groups.google.ca/group/comp.lang.python/msg/a80fcd8932b0733a
> >
> > It's clean, does the job, and doesn't have any extra nesting.
> >
> > Peace,
> > ~Simon
> >
>
> I remember that versi
Boris Borcic wrote:
> John Salerno wrote:
>> In this case the method must return False, because it's a wxPython
>> method that needs a True or False value. If it doesn't, the program
>> will continue even after the error message.
>
> Just as it should do if the method returns True and no error m
John Salerno wrote:
> In this case the method must return False, because it's a wxPython
> method that needs a True or False value. If it doesn't, the program will
> continue even after the error message.
Just as it should do if the method returns True and no error message is
produced
if I und
Bruno Desthuilliers wrote:
> Boris Borcic a écrit :
>> Slawomir Nowaczyk wrote:
>>
>>>
>>> try:
>>> if int(text) > 0:
>>>return True
>>> except ValueError:
>>> pass
>>> self.error_message()
>>> return False
>>>
>>
>> Nicely DRY. To make it even more compact, it may be noticed that t
Boris Borcic wrote:
> Slawomir Nowaczyk wrote:
>>
>> try:
>> if int(text) > 0:
>>return True
>> except ValueError:
>> pass
>> self.error_message()
>> return False
>>
>
> Nicely DRY. To make it even more compact, it may be noticed that the
> default return value None is false in a
Boris Borcic a écrit :
> Slawomir Nowaczyk wrote:
>
>>
>> try:
>> if int(text) > 0:
>>return True
>> except ValueError:
>> pass
>> self.error_message()
>> return False
>>
>
> Nicely DRY. To make it even more compact, it may be noticed that the
> default return value None is false
Slawomir Nowaczyk wrote:
>
> try:
> if int(text) > 0:
>return True
> except ValueError:
> pass
> self.error_message()
> return False
>
Nicely DRY. To make it even more compact, it may be noticed that the default
return value None is false in a boolean context - so that the last
On Thu, 10 Aug 2006 14:32:49 + (GMT)
John Salerno <[EMAIL PROTECTED]> wrote:
#> Bruno Desthuilliers wrote:
#>
#> > try:
#> > if int(text) <= 0: raise ValueError
#>
#> Hmm, I'm actually not so sure about this line now. It doesn't seem right
#> to raise a ValueError when the res
John Salerno a écrit :
> Bruno Desthuilliers wrote:
>
>> try:
>> if int(text) <= 0: raise ValueError
>
>
> Hmm, I'm actually not so sure about this line now. It doesn't seem right
> to raise a ValueError when the result of the expression is negative,
> because even though it's a
> > try:
> > if int(text) <= 0: raise ValueError
>
> Hmm, I'm actually not so sure about this line now. It doesn't seem right
> to raise a ValueError when the result of the expression is negative,
> because even though it's a problem for my program, it isn't really a
> "ValueError," r
On Wed, 09 Aug 2006 18:51:04 + (GMT)
John Salerno <[EMAIL PROTECTED]> wrote:
#> try:
#> int(text)
#> except ValueError:
#> self.error_message()
#> return False
#> else:
#> return True
#>
#> I think it's much cleaner, but obviously I lost the test in the
#> original if stat
Bruno Desthuilliers wrote:
> try:
> if int(text) <= 0: raise ValueError
Hmm, I'm actually not so sure about this line now. It doesn't seem right
to raise a ValueError when the result of the expression is negative,
because even though it's a problem for my program, it isn't really
Simon Forman wrote:
> What about the version I gave you 8 days ago? ;-)
>
> http://groups.google.ca/group/comp.lang.python/msg/a80fcd8932b0733a
>
> It's clean, does the job, and doesn't have any extra nesting.
>
> Peace,
> ~Simon
>
I remember that version, but I found it a little hard to foll
Bruno Desthuilliers wrote:
> try:
> if int(text) <= 0: raise ValueError
> except ValueError:
> self.error_message()
> return False
> else:
> return True
Nice! Thanks!
--
http://mail.python.org/mailman/listinfo/python-list
Bruno Desthuilliers a écrit :
> John Salerno a écrit :
>
(snip)
or of course the dead simple:
try:
if int(text) <= 0: raise ValueError
except ValueError:
self.error_message()
return False
else:
return True
BTW, you really should have a
John Salerno wrote:
> I'm starting out with this:
>
> try:
> if int(text) > 0:
> return True
> else:
> self.error_message()
> return False
> except ValueError:
> self.error_message()
> return False
>
> I rewrote it as this:
>
> try:
> int(text)
>
John Salerno a écrit :
> I'm starting out with this:
>
> try:
> if int(text) > 0:
> return True
> else:
> self.error_message()
> return False
> except ValueError:
> self.error_message()
> return False
>
> I rewrote it as this:
>
> try:
> int(text)
> ex
I'm starting out with this:
try:
if int(text) > 0:
return True
else:
self.error_message()
return False
except ValueError:
self.error_message()
return False
I rewrote it as this:
try:
int(text)
except ValueError:
self.error_message()
r
32 matches
Mail list logo