Is try-except slow?

2008-09-02 Thread ssecorp
or why does this take so god damn long time? and if I run into an IndexError it break out of the inner loop right? so having range up to 1000 or 1000 wouldn't matter if biggest working x is 800? def getPixels(fileName): im = PIL.Image.open(fileName) colors = [] for y in range(1, 10

Re: Is try-except slow?

2008-09-02 Thread Robert Kern
ssecorp wrote: or why does this take so god damn long time? Several reasons. One of which is that try: except: is slow. and if I run into an IndexError it break out of the inner loop right? so having range up to 1000 or 1000 wouldn't matter if biggest working x is 800? try: except: need

Re: Is try-except slow?

2008-09-02 Thread John Machin
On Sep 3, 9:44 am, ssecorp <[EMAIL PROTECTED]> wrote: > or why does this take so god damn long time? Because your code does so many god damn unnecessary things. Apart from the fact (as pointed out already by Robert) that you are needlessly finding the sizes (Y, X) that are already available: (1)

Re: Is try-except slow?

2008-09-02 Thread process
On Sep 3, 2:36 am, John Machin <[EMAIL PROTECTED]> wrote: > On Sep 3, 9:44 am, ssecorp <[EMAIL PROTECTED]> wrote: > > > or why does this take so god damn long time? > > Because your code does so many god damn unnecessary things. Apart from > the fact (as pointed out already by Robert) that you are

Re: Is try-except slow?

2008-09-02 Thread process
is this faster btw? I guess big doesn't help, it's only retrieved once anyway? But is rows retrieved in every loop? the python interpreter aint too smart? def getPixels(fileName): im = PIL.Image.open(fileName) colors = [] r, c = im.size big = range(0, c) rows = range(0, r)

Re: Is try-except slow?

2008-09-02 Thread John Machin
On Sep 3, 11:00 am, process <[EMAIL PROTECTED]> wrote: > how could I do getpixel once when x and y s changing? I was not referring to *calling* im.getpixel, I was referring to looking up getpixel as an attribute of im. How? See below. > > anyway I rewrote and saw I did a lot of stupid stuff. this

Re: Is try-except slow?

2008-09-02 Thread John Machin
On Sep 3, 11:14 am, process <[EMAIL PROTECTED]> wrote: > is this faster btw? Time it and see. > I guess big doesn't help, it's only retrieved once > anyway? Correct. > But is rows retrieved in every loop? Of course. Read your own code! The point is that retrieving the list referenced by "rows"

Re: Is try-except slow?

2008-09-02 Thread Steven D'Aprano
On Tue, 02 Sep 2008 18:56:48 -0500, Robert Kern wrote: > ssecorp wrote: >> or why does this take so god damn long time? > > Several reasons. One of which is that try: except: is slow. I beg to differ. Setting up a try...except block is very fast. Here's an example in Python 2.5: >>> from tim

Re: Is try-except slow?

2008-09-03 Thread Fredrik Lundh
process wrote: is this faster btw? I guess big doesn't help, it's only retrieved once anyway? But is rows retrieved in every loop? the python interpreter aint too smart? > def getPixels(fileName): im = PIL.Image.open(fileName) colors = [] r, c = im.size big = range(0, c) ro

Re: Is try-except slow?

2008-09-03 Thread Robert Kern
Steven D'Aprano wrote: On Tue, 02 Sep 2008 18:56:48 -0500, Robert Kern wrote: ssecorp wrote: or why does this take so god damn long time? Several reasons. One of which is that try: except: is slow. I beg to differ. Setting up a try...except block is very fast. Here's an example in Python