On Sunday, 7 October 2012 01:12:56 UTC+5:30, Terry Reedy wrote:
> On 10/6/2012 7:36 AM, Dave Angel wrote:
>
>
>
> > The distinction in performance between the success and failure modes of
>
> > the try/catch isn't nearly as large as one of the other responses might
>
> > lead you to believe.
On 10/6/2012 7:36 AM, Dave Angel wrote:
The distinction in performance between the success and failure modes of
the try/catch isn't nearly as large as one of the other responses might
lead you to believe. For example, a for loop generally terminates with
a raise (of StopIteration exception), an
On 10/06/2012 02:27 AM, Manuel Pégourié-Gonnard wrote:
> Hi,
>
> I was looking at the example found here [1] which begins with:
>
> [1] http://docs.python.org/py3k/library/imp.html#examples
>
> def __import__(name, globals=None, locals=None, fromlist=None):
> # Fast path: see if the module has
Steven D'Aprano scripsit :
> If you expect that most of the time the module will be found, the
> try...except version will be faster. If you expect that most of the time
> the module will not be found, the "if name in" version will be faster.
>
Ok.
In the particular case of __import__, I guess
Günther Dietrich scripsit :
> Somewhere I read a text regarding 'try:' versus 'if'. If you take the
> probabitility into consideration, how many times the test will fail or
> succeed, there are two possibilities: [...]
Ok, thanks for the details!
--
Manuel Pégourié-Gonnard - http://people.mat
Manuel Pégourié-Gonnard wrote:
>Hi,
>I was looking at the example found here [1] which begins with:
>
>[1] http://docs.python.org/py3k/library/imp.html#examples
>
>def __import__(name, globals=None, locals=None, fromlist=None):
># Fast path: see if the module has already been imported.
>t
On Sat, 06 Oct 2012 08:27:25 +0200, Manuel Pégourié-Gonnard wrote:
> Hi,
>
> I was looking at the example found here [1] which begins with:
>
> [1] http://docs.python.org/py3k/library/imp.html#examples
>
> def __import__(name, globals=None, locals=None, fromlist=None):
> # Fast path: see if
Hi,
I was looking at the example found here [1] which begins with:
[1] http://docs.python.org/py3k/library/imp.html#examples
def __import__(name, globals=None, locals=None, fromlist=None):
# Fast path: see if the module has already been imported.
try:
return sys.modules[name]