Re: Exceptions versus Windows ERRORLEVEL

2020-04-06 Thread Stephen Tucker
Thanks, Eryk - this is very helpful. Stephen. On Mon, Apr 6, 2020 at 6:43 AM Eryk Sun wrote: > On 4/3/20, Stephen Tucker wrote: > > > > Does an exception raised by a Python 3.x program on a Windows machine set > > ERRORLEVEL? > > ERRORLEVEL is an internal state of the CMD shell. It has nothing

Re: Exceptions versus Windows ERRORLEVEL

2020-04-05 Thread Eryk Sun
On 4/3/20, Stephen Tucker wrote: > > Does an exception raised by a Python 3.x program on a Windows machine set > ERRORLEVEL? ERRORLEVEL is an internal state of the CMD shell. It has nothing to do with Python. If Python exits due to an unhandled exception, the process exit code will be 1. If CMD w

Re: Exceptions versus Windows ERRORLEVEL

2020-04-04 Thread Luuk
On 3-4-2020 02:08, Stephen Tucker (Stephen Tucker) wrote: Hi, I have found that raising an exception in a Python 2.7.10 program running under Windows does not set ERRORLEVEL. I realise that Python 2.x is no longer supported. Does an exception raised by a Python 3.x program on a Windows machine

Re: Exceptions are not just for errors

2010-10-14 Thread Gregory Ewing
Ben Finney wrote: Another way of thinking about it is that there's no sensible sequence of bytes to return at EOF, so the Pythonic thing to do is to raise an exception for this exceptional circumstance. But this is *not* what Python does, so it's obviously not Pythonic. :-) If f.read(n) is to

Re: Exceptions are not just for errors (was: My first Python program)

2010-10-13 Thread Emmanuel Surleau
> Seebs writes: > > On 2010-10-13, Chris Rebert wrote: > > > For future reference, the significant majority of things in Python > > > raise exceptions upon encountering errors rather than returning > > > error values of some sort. > > > > Yes. I'm getting used to that -- it's a bit of a shift,

Re: exceptions and unicode

2010-06-19 Thread Stuart McGraw
On 06/16/2010 03:51 PM, Thomas Jollans wrote: > On 06/16/2010 10:10 PM, Stuart McGraw wrote: >> Note that the exceptions may be anything (I just used IOError >> as an example) and are generated in bowels of an API that I >> can't/won't mess with. > > Yeah, well, you'd have to special-case every

Re: exceptions and unicode

2010-06-19 Thread Stuart McGraw
On 06/16/2010 03:53 PM, Martin v. Loewis wrote: >> So how do I get what I want? > > Submit a patch. You would have to explain why this is a bug fix and not > a new feature, as new features are not allowed anymore for 2.x. Thanks. Actually I have no idea if this is a bug or a feature (despite r

Re: exceptions and unicode

2010-06-16 Thread Martin v. Loewis
So how do I get what I want? Submit a patch. You would have to explain why this is a bug fix and not a new feature, as new features are not allowed anymore for 2.x. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list

Re: exceptions and unicode

2010-06-16 Thread Thomas Jollans
On 06/16/2010 10:10 PM, Stuart McGraw wrote: > I am having a problem with exceptions and unicode. > > try: open ('file.txt') > except IOError, e: pass > str (e) > => "[Errno 2] No such file or directory: 'file.txt'" > > which is fine but... > > try: open (u'フィイル.txt') > except IOErro

Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-19 Thread Aahz
In article , Steven D'Aprano wrote: > >Additionally, while I'm a fan of the simplicity of CPython's ref counter, >one serious side effect of it is that it requires the GIL, which >essentially means CPython is crippled on multi-core CPUs compared to non- >ref counting implementations. Your bare

Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-18 Thread Piet van Oostrum
> Charles Yeomans (CY) wrote: >CY> Memory management may be an "implementation detail", but it is >CY> unfortunately one that illustrates the so-called law of leaky >CY> abstractions. So I think that one has to write code that follows the >CY> memory management scheme of whatever language on

Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-17 Thread Steven D'Aprano
On Wed, 17 Jun 2009 22:58:27 -0400, Charles Yeomans wrote: > On Jun 17, 2009, at 9:43 PM, Steven D'Aprano wrote: > >> On Wed, 17 Jun 2009 07:49:52 -0400, Charles Yeomans wrote: >> Even CPython doesn't rely completely on reference counting (it has a fallback gc for cyclic garbage). Pyth

Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-17 Thread Charles Yeomans
On Jun 17, 2009, at 9:43 PM, Steven D'Aprano wrote: On Wed, 17 Jun 2009 07:49:52 -0400, Charles Yeomans wrote: Even CPython doesn't rely completely on reference counting (it has a fallback gc for cyclic garbage). Python introduced the "with" statement to get away from the kludgy CPython prog

Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-17 Thread Steven D'Aprano
On Wed, 17 Jun 2009 23:29:48 +1200, Lawrence D'Oliveiro wrote: > In message <7x7hzbv14a@ruckus.brouhaha.com>, wrote: > >> Lawrence D'Oliveiro writes: >> >>> > Reference counting is an implementation detail used by CPython but >>> > not [implementations built on runtimes designed for >>> > c

Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-17 Thread Steven D'Aprano
On Wed, 17 Jun 2009 07:49:52 -0400, Charles Yeomans wrote: >> Even CPython doesn't rely completely on reference counting (it has a >> fallback gc for cyclic garbage). Python introduced the "with" >> statement to get away from the kludgy CPython programmer practice of >> opening files and relying

Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-17 Thread Charles Yeomans
On Jun 17, 2009, at 2:13 AM, Paul Rubin wrote: Lawrence D'Oliveiro writes: Reference counting is an implementation detail used by CPython but not [implementations built on runtimes designed for corporate-herd- oriented languages, like] IronPython or Jython. I rest my case. You're reall

Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-17 Thread Lawrence D'Oliveiro
In message <7x7hzbv14a@ruckus.brouhaha.com>, wrote: > Lawrence D'Oliveiro writes: > >> > Reference counting is an implementation detail used by CPython but not >> > [implementations built on runtimes designed for corporate-herd-oriented >> > languages, like] IronPython or Jython. >> >> I re

Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-16 Thread Steven D'Aprano
On Wed, 17 Jun 2009 17:52:30 +1200, Lawrence D'Oliveiro wrote: > In message , > Steven D'Aprano wrote: > >> On Tue, 16 Jun 2009 16:45:43 +1200, Lawrence D'Oliveiro wrote: >> >>> In message , Piet van Oostrum wrote: >>> The exact time of the destruction of objects is an implementation

Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-16 Thread Paul Rubin
Lawrence D'Oliveiro writes: > > Reference counting is an implementation detail used by CPython but not > > [implementations built on runtimes designed for corporate-herd-oriented > > languages, like] IronPython or Jython. > > I rest my case. You're really being pretty ignorant. I don't know of

Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-16 Thread Lawrence D'Oliveiro
In message , Steven D'Aprano wrote: > On Tue, 16 Jun 2009 16:45:43 +1200, Lawrence D'Oliveiro wrote: > >> In message , Piet van Oostrum wrote: >> >>> The exact time of the destruction of objects is an implementation >>> detail and should not be relied upon. >> >> That may be true in Java and o

Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-16 Thread Steven D'Aprano
On Tue, 16 Jun 2009 16:45:43 +1200, Lawrence D'Oliveiro wrote: > In message , Piet van Oostrum wrote: > >> The exact time of the destruction of objects is an implementation >> detail and should not be relied upon. > > That may be true in Java and other corporate-herd-oriented languages, > but we

Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-15 Thread Lawrence D'Oliveiro
In message , Piet van Oostrum wrote: > The exact time of the destruction of objects is an implementation detail > and should not be relied upon. That may be true in Java and other corporate-herd-oriented languages, but we know that dynamic languages like Perl and Python make heavy use of refere

Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-13 Thread Mike Kazantsev
On Fri, 12 Jun 2009 18:33:13 -0400 Nikolaus Rath wrote: > Nikolaus Rath writes: > > Hi, > > > > Please consider this example: > [] > > I think I managed to narrow down the problem a bit. It seems that when > a function returns normally, its local variables are immediately > destroyed. Howev

Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-13 Thread Aahz
In article <873aa5m6ae@vostro.rath.org>, Nikolaus Rath wrote: > >I think I managed to narrow down the problem a bit. It seems that when >a function returns normally, its local variables are immediately >destroyed. However, if the function is left due to an exception, the >local variables rema

Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-13 Thread Piet van Oostrum
> Nikolaus Rath (NR) wrote: >NR> Is there a way to have the obj variable (that is created in dostuff()) >NR> destroyed earlier than at the end of the program? As you can see, I >NR> already tried to explicitly call the garbage collector, but this does >NR> not help. The exact time of the des

Re: Exceptions and Object Destruction

2009-06-12 Thread MRAB
Nikolaus Rath wrote: Nikolaus Rath writes: Hi, Please consider this example: [] I think I managed to narrow down the problem a bit. It seems that when a function returns normally, its local variables are immediately destroyed. However, if the function is left due to an exception, the loc

Re: Exceptions on delete in pysqlite

2008-01-27 Thread Wildemar Wildenburger
Gabriel Genellina wrote: > En Fri, 25 Jan 2008 22:12:57 -0200, Wildemar Wildenburger > <[EMAIL PROTECTED]> escribi�: > >> Using pysqlite, I'd like to check if some dataset that I removed has >> been in the database at all. Ideally I'd like pysqlite to raise an >> Exception if deleting does nothin

Re: Exceptions on delete in pysqlite

2008-01-27 Thread Gabriel Genellina
En Fri, 25 Jan 2008 22:12:57 -0200, Wildemar Wildenburger <[EMAIL PROTECTED]> escribi�: > Using pysqlite, I'd like to check if some dataset that I removed has > been in the database at all. Ideally I'd like pysqlite to raise an > Exception if deleting does nothing. Is that possible? I don't thi

Re: Exceptions - How do you make it work like built-in exceptions?

2008-01-14 Thread Lie
On Jan 14, 1:51 am, "Mark Tolonen" <[EMAIL PROTECTED]> wrote: > "Lie" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > > > > >A built-in exceptions, when raised, would print traceback that points > > out the offending code, like this: > > > Traceback (most recent call last): > >  F

Re: Exceptions - How do you make it work like built-in exceptions?

2008-01-13 Thread Mark Tolonen
"Lie" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >A built-in exceptions, when raised, would print traceback that points > out the offending code, like this: > > Traceback (most recent call last): > File "F:\dir\code.py", line 43, in >a = 1/0 <<<--- > ZeroDivisionError: inte

Re: Exceptions - How do you make it work like built-in exceptions?

2008-01-13 Thread Chris
On Jan 13, 4:14 pm, Lie <[EMAIL PROTECTED]> wrote: > A built-in exceptions, when raised, would print traceback that points > out the offending code, like this: > > Traceback (most recent call last): > File "F:\dir\code.py", line 43, in > a = 1/0 <<<--- > ZeroDivisionError: integer division o

Re: Exceptions: Logging TB and local variables?

2007-10-10 Thread allen.fowler
> Two possibilieies: > > You will need to determine ALL the exceptions that the 3rd party party modules > can raise. If they are custom exceptions you will need to import them into > your > application from their modules. > > example: > > say that 3rd party modules raise TransientError, IOError,

Re: Exceptions: Logging TB and local variables?

2007-10-10 Thread Larry Bates
allen.fowler wrote: > 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.__

Re: Exceptions and unicode messages

2007-03-21 Thread Tuomas
This seems to work: >>> import sys, traceback >>> def excepthook(exctype, value, tb): ... if tb: ... lines = traceback.format_tb(tb) ... for i, line in zip(range(len(lines)), lines): ... lines[i] = lines[i].decode('utf8') ... lines.insert(0, u'Traceback (

Re: Exceptions and unicode messages

2007-03-21 Thread kyosohma
On Mar 21, 6:03 am, Tuomas <[EMAIL PROTECTED]> wrote: > This works: > >>> raise StandardError(u'Wrong type') > Traceback (most recent call last): >File "", line 1, in ? > StandardError: Wrong type > > but don't in Finnish: > >>> raise StandardError(u'Väärä tyyppi') > Traceback (most recent ca

Re: Exceptions and unicode messages

2007-03-21 Thread kyosohma
On Mar 21, 6:03 am, Tuomas <[EMAIL PROTECTED]> wrote: > This works: > >>> raise StandardError(u'Wrong type') > Traceback (most recent call last): >File "", line 1, in ? > StandardError: Wrong type > > but don't in Finnish: > >>> raise StandardError(u'Väärä tyyppi') > Traceback (most recent ca

Re: Exceptions and unicode messages

2007-03-21 Thread manish kurup
Hey anybody please tell me... How we can get the properties of a file in python On 3/21/07, Tuomas <[EMAIL PROTECTED]> wrote: This works: >>> raise StandardError(u'Wrong type') Traceback (most recent call last): File "", line 1, in ? StandardError: Wrong type but don't in Finnish: >>> r

Re: Exceptions when closing a file

2007-03-20 Thread Ben Finney
John Nagle <[EMAIL PROTECTED]> writes: > If you want to force [an error while closing a file], write to > a drive reached over a network, or a removable medium like a floppy > or flash card. Open a file for writing and disconnect the network > or remove the removable medium. Or simply use a

Re: Exceptions when closing a file

2007-03-20 Thread kyosohma
On Mar 20, 4:26 pm, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] a écrit : > > > > > On Mar 20, 12:25 pm, Steven D'Aprano > > <[EMAIL PROTECTED]> wrote: > > >>Closing a file can (I believe) raise an exception. Is that documented > >>anywhere? I've spent a lot of frustrating ti

Re: Exceptions when closing a file

2007-03-20 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > On Mar 20, 12:25 pm, Steven D'Aprano > <[EMAIL PROTECTED]> wrote: > >>Closing a file can (I believe) raise an exception. Is that documented >>anywhere? I've spent a lot of frustrating time trying to track this down, >>with no luck, which suggests that either my google

Re: Exceptions when closing a file

2007-03-20 Thread John Nagle
Ross Ridge wrote: > Steven D'Aprano <[EMAIL PROTECTED]> wrote: > >>Closing a file can (I believe) raise an exception. Is that documented >>anywhere? > > > In a catch-all statement for file objects: "When a file operation fails > for an I/O-related reason, the exception IOError is raised." The

Re: Exceptions when closing a file

2007-03-20 Thread Ross Ridge
Steven D'Aprano <[EMAIL PROTECTED]> wrote: >Closing a file can (I believe) raise an exception. Is that documented >anywhere? In a catch-all statement for file objects: "When a file operation fails for an I/O-related reason, the exception IOError is raised." The fact that close() is a file opera

Re: Exceptions when closing a file

2007-03-20 Thread kyosohma
On Mar 20, 12:25 pm, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > Closing a file can (I believe) raise an exception. Is that documented > anywhere? I've spent a lot of frustrating time trying to track this down, > with no luck, which suggests that either my google-foo is weak or that it > isn't doc

Re: Exceptions

2006-02-21 Thread DavidPorterHolt
That's good to know. Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: Exceptions

2006-02-21 Thread Paul McGuire
"DavidPorterHolt" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Here's the same clip, but run in the command line interpreter. The > error gives a little more info. > > >>> try: > ... fsock = open('/notthere') > ... except IOError: > ... print 'The file does not exist, exiti

Re: Exceptions

2006-02-21 Thread DavidPorterHolt
Here's the same clip, but run in the command line interpreter. The error gives a little more info. >>> try: ... fsock = open('/notthere') ... except IOError: ... print 'The file does not exist, exiting gracefully' ... print 'This line will always print' File "", line 5 print 'This li

Re: exceptions, internals (introspection?)

2005-11-10 Thread Fernando Perez
ej wrote: > I have often wondered how to get at other internals, such as the name of > the current function, file, line number I am in? The arguments to the > current function, etc. I browsed through the table of contents of both the > Library Reference & Language Reference. I see section 18

Re: exceptions, internals (introspection?)

2005-11-10 Thread Paul Rubin
"ej" writes: > for key in dir(traceback_): > print "traceback_.%s =" % key, eval("traceback_.%s" % key) Don't use eval for this. Use getattr(traceback_, key). > traceback_.tb_frame = > traceback_.tb_lasti = 18 > traceback_.tb_lineno = 6 > traceback_.tb_next = None Yeah. As /F men

Re: exceptions, internals (introspection?)

2005-11-10 Thread ej
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > the second example on this page shows you how to do that: > > http://effbot.org/librarybook/traceback I am looking at it. Thanks for your prompt reply, Mr. Lundh! :) -ej -- http://mail.python.org/mailman/listinf

Re: exceptions, internals (introspection?)

2005-11-10 Thread ej
"Paul Rubin" wrote in message news:[EMAIL PROTECTED] > It's messy. Look at sys.exc_info() and go from there. Yeah, I think I am starting to see what you mean... #! /usr/local/bin/python import sys try: {}['foo'] except Exception, x: print "class of x =", x._

Re: exceptions, internals (introspection?)

2005-11-10 Thread Paul McNett
ej wrote: > I have often wondered how to get at other internals, such as the name of > the current function, file, line number I am in? The arguments to the > current function, etc. Others have given you information on how to get at the stack trace. But regarding getting at some of the othe

Re: exceptions, internals (introspection?)

2005-11-10 Thread Paul Rubin
"ej" writes: > I have often wondered how to get at other internals, such as the name of > the current function, file, line number I am in? The arguments to the > current function, etc. It's messy. Look at sys.exc_info() and go from there. -- http://mail.python.org/mailman/listinfo/python-

Re: exceptions, internals (introspection?)

2005-11-10 Thread Fredrik Lundh
"ej" <"ej atwellkeepercom"@bag.python.org> wrote > try: >{}['foo'] > except Exception, x: >print "class of x =", x.__class__ >print "type(x) =", type(x) >print "dir(x) =", dir(x) > >If you don't handle an exception, the interpreter will quit and print a > stack trace. What I'm

Re: exceptions from logging on Windows

2005-09-12 Thread Simon Dahlbacka
I ended up monkey-patching doRollover to do a number of retries before giving up. (In our case the failures is due to our log browser happening to read the latest changes when logging wants to rollover) (Actually, I implemented a simple QueueHandler and do all file operations from a different logg

Re: exceptions considered harmful

2005-06-18 Thread Andrea Griffini
On Fri, 17 Jun 2005 20:00:39 -0400, Roy Smith <[EMAIL PROTECTED]> wrote: >This sounds like a very C++ view of the world. In Python, for example, >exceptions are much more light weight and perfectly routine. The problem with exceptions is coping with partial updatd state. Suppose you call a comp

Re: exceptions considered harmful

2005-06-18 Thread Steven D'Aprano
On Fri, 17 Jun 2005 20:00:39 -0400, Roy Smith wrote: > "H. S. Lahman" <[EMAIL PROTECTED]> wrote: >> > Never throw an exception. And if someone throws one at you, >> > catch it immediately and don't pass it on. >> >> IMO, this is generally fine advice. Languages provide exception >> hand

Re: exceptions considered harmful

2005-06-17 Thread Roy Smith
"H. S. Lahman" <[EMAIL PROTECTED]> wrote: > > Never throw an exception. And if someone throws one at you, > > catch it immediately and don't pass it on. > > IMO, this is generally fine advice. Languages provide exception > handlers so that applications have a chance to respond gracefully

Re: exceptions and items in a list

2005-01-10 Thread vincent wehren
Steve Holden wrote: vincent wehren wrote: rbt wrote: If I have a Python list that I'm iterating over and one of the objects in the list raises an exception and I have code like this: try: do something to object in list except Exception: pass Does the code just skip the bad object and cont

Re: exceptions and items in a list

2005-01-10 Thread Steve Holden
vincent wehren wrote: rbt wrote: If I have a Python list that I'm iterating over and one of the objects in the list raises an exception and I have code like this: try: do something to object in list except Exception: pass Does the code just skip the bad object and continue with the other

Re: exceptions and items in a list

2005-01-10 Thread Peter Hansen
rbt wrote: Andrey Tatarinov wrote: # skip bad object and continue with others for object in objects: try: #do something to object except Exception: pass Thanks Andrey. That's a great example of how to do it. Actually, it's not really a "great" example, since it catches _all_

Re: exceptions and items in a list

2005-01-10 Thread rbt
Andrey Tatarinov wrote: rbt wrote: If I have a Python list that I'm iterating over and one of the objects in the list raises an exception and I have code like this: try: do something to object in list except Exception: pass Does the code just skip the bad object and continue with the othe

Re: exceptions and items in a list

2005-01-10 Thread vincent wehren
rbt wrote: If I have a Python list that I'm iterating over and one of the objects in the list raises an exception and I have code like this: try: do something to object in list except Exception: pass Does the code just skip the bad object and continue with the other objects in the list,

Re: exceptions and items in a list

2005-01-10 Thread Andrey Tatarinov
rbt wrote: If I have a Python list that I'm iterating over and one of the objects in the list raises an exception and I have code like this: try: do something to object in list except Exception: pass Does the code just skip the bad object and continue with the other objects in the list,