Re: Returning to 'try' block after catching an exception

2008-05-22 Thread Jake Anderson

alex23 wrote:

On May 22, 9:13 am, Karlo Lozovina <[EMAIL PROTECTED]> wrote:
  

In case it's not clear what I meant: after executing some_function()
exception SomeExcpetion gets risen. Then, in except block I do something
to fix whatever is causing the exception and then I would like to go back
to try block, and execute some_function() again. Is that doable?



If you know what exception to expect, and you know how to "fix" the
cause, why not just put tests _before_ some_function() is called to
ensure that everything is as it needs to be?
--
http://mail.python.org/mailman/listinfo/python-list
  

There are cases where this could be helpful
FTP upload that would sometimes get cut off along the way. So you might 
want to just try again depending on why the failure happened perhaps.


Command of "ReTry" sounds good to me ;->
--
http://mail.python.org/mailman/listinfo/python-list

Re: python scalability

2008-07-09 Thread Jake Anderson

Tim Mitchell wrote:

Hi All,

I work on a desktop application that has been developed using python 
and GTK (see www.leapfrog3d.com).  We have around 150k lines of python 
code (and 200k+ lines of C).  We also have a new project manager with 
a C# background who has deep concerns about the scalability of python 
as our code base continues to grow and we are looking at introducing 
more products.  I am looking for examples of other people like us (who 
write desktop apps in python) with code bases of a similar size who I 
can point to (and even better talk to) to help convince him that 
python is scalable to 300+ lines of code and beyond.  I have looked at 
the python success stories page and haven't come up with anyone quite 
like us. One of my project managers questions is: "Are we the only 
company in the world with this kind and size of project?"

I want to say no, but am having trouble convincing myself, let alone him.

If you are involved in this kind of thing please get in touch with me.

Thanks,
Tim
--
http://mail.python.org/mailman/listinfo/python-list

It'd be 1500k lines of C if not for the 150k of python ;->
--
http://mail.python.org/mailman/listinfo/python-list


Re: very large dictionary

2008-08-06 Thread Jake Anderson

Bruno Desthuilliers wrote:

Simon Strobl a écrit :
(snip)
> I would prefer to be able to use the same type of

scripts with data of all sizes, though.


Since computers have a limited RAM, this is to remain a wish. You 
can't obviously expect to deal with terabytes of data like you do with 
a 1kb text file.

--
http://mail.python.org/mailman/listinfo/python-list

You can, you just start off handling the multi GB case and your set.
databases are really easy, I often use them for manipulating pretty 
small amounts of data because its just an easy way to group and join etc.


--
http://mail.python.org/mailman/listinfo/python-list


Re: benchmark

2008-08-06 Thread Jake Anderson

Jack wrote:
I know one benchmark doesn't mean much but it's still disappointing to see 
Python as one of the slowest languages in the test:


http://blog.dhananjaynene.com/2008/07/performance-comparison-c-java-python-ruby-jython-jruby-groovy/ 



--
http://mail.python.org/mailman/listinfo/python-list
  
Something to note though, The python version is ~ half the length of the 
rest of them ;->

--
http://mail.python.org/mailman/listinfo/python-list


Re: Upgrading to DB-API (was Re: Corrupted images ...)

2008-08-13 Thread Jake Anderson

Aahz wrote:

In article <[EMAIL PROTECTED]>,
Fredrik Lundh  <[EMAIL PROTECTED]> wrote:
  
Ouch.  Please use parameters instead of explicit escapes and string 
formatting; Python's not PHP.



How would you recommend upgrading an application that is more than ten
years old and contains something like 100K lines of code?
  

Very carefully? ;->
It would be a manual process but it shouldn't be too bad, the stuff 
before and after that code block should be unaffected
--
http://mail.python.org/mailman/listinfo/python-list

Re: improving a huge double-for cycle

2008-09-18 Thread Jake Anderson




psyco might help a fair bit (10x-40x) here ;->
perhaps look at dumping the data into sqlite then pulling it back out.
It (or the other databases) are designed for tossing around large lumps
of data.
Alexzive wrote:

  Hello there :) ,

I am a python newbie and need to run following code for a task in an
external simulation programm called "Abaqus" which makes use of python
to access the mesh (ensamble of nodes with xy coordinates) of a
certain geometrical model.

[IN is the starting input containing the nodes to be check, there are
some double nodes with the same x and y coordinates which need to be
removed. SN is the output containing such double nodes]

Code: Select all
for i in range(len(IN)): #scan all elements of the list IN
  for j in range(len(IN)):
if i <> j:
 if IN[i].coordinates[0] == IN[j].coordinates[0]:
   if IN[i].coordinates[1] == IN[j].coordinates[1]:
  SN.append(IN[i].label)



Unfortunately my len(IN) is about 100.000 and the running time about
15h  :(

Any idea to improve it?

I have already tried to group the "if statements" in a single one:

Code: Select all
if i <> j and if IN[i].coordinates[0] == IN[j].coordinates[0] and
if IN[i].coordinates[1] == IN[j].coordinates[1]:


but no improvements.

Many thanks, Alex
--
http://mail.python.org/mailman/listinfo/python-list
  



-- 


Vapour Forge



Jake Anderson


Project Manager


Mobile:   0412 897 125
Email: [EMAIL PROTECTED]
Web Page:  www.vapourforge.com


Your source
for custom IT services




--
http://mail.python.org/mailman/listinfo/python-list

Re: improving a huge double-for cycle

2008-09-19 Thread Jake Anderson

Bruno Desthuilliers wrote:

Alexzive a écrit :

Hello there :) ,

I am a python newbie and need to run following code for a task in an
external simulation programm called "Abaqus" which makes use of python
to access the mesh (ensamble of nodes with xy coordinates) of a
certain geometrical model.

[IN is the starting input containing the nodes to be check, there are
some double nodes with the same x and y coordinates which need to be
removed. SN is the output containing such double nodes]

Code: Select all
for i in range(len(IN)): #scan all elements of the list IN
  for j in range(len(IN)):
if i <> j:
 if IN[i].coordinates[0] == IN[j].coordinates[0]:
   if IN[i].coordinates[1] == IN[j].coordinates[1]:
  SN.append(IN[i].label)



Unfortunately my len(IN) is about 100.000 and the running time about
15h  :(

Any idea to improve it?


A couple ones have been submitted. Harald gets a point about the 
redundant tests (even if his solution seems to be broken, cf below) - 
your inner loop should have looked like :


  for j in xrange(i+1, len(IN))

Now the obvious winner is pruebono - even unoptimized, using sets seems 
to be *way* faster than even the most optimized corrected version of 
your algorithm.


Here's a quick bench - please everyone doublecheck it to make sure it's ok:




Results here (py2.5, gentoo linux, athlonxp1800, 512 ram):

 >>> test_results()
True
 >>> test_times()
doubles0 : 1.55667901039
doubles1 : 0.719144105911
doubles2 : 0.703393936157
doubles3 : 0.700654983521
doubles4 : 0.706257104874
doubles5 : 0.528184890747
doubles6 : 0.461633205414
doubles8 : 0.0134379863739
doubles9 : 0.0108540058136
 >>>

Not surprisingly, half less iterations makes for half less time. 
Aliasing, as often, proves to be a good optimization too. But obviously, 
using the correct data structure / algorithm combo is the key : simpler 
code, and 115 times faster (143 times with aliasing). If pruebono 
solution's is correct (and it as AFAICT), your 15 hours computation 
should by now take less than 10 minutes...





Ubuntu 8.04 core2 2.6(i think)
without psycho
doubles0 : 0.610555171967
doubles1 : 0.29314494133
doubles2 : 0.286273956299
doubles3 : 0.281984090805
doubles4 : 0.28240609169
doubles5 : 0.207377910614
doubles6 : 0.156388044357
doubles8 : 0.00533080101013
doubles9 : 0.00458884239197

with psycho
doubles0 : 0.127684116364
doubles1 : 0.069571018219
doubles2 : 0.064826965332
doubles3 : 0.0702300071716
doubles4 : 0.0647261142731
doubles5 : 0.0522589683533
doubles6 : 0.0437579154968
doubles8 : 0.00190806388855
doubles9 : 0.00214099884033

On this small test its a variance between ~6x to 2X still its basically 
free so why not ;->

--
http://mail.python.org/mailman/listinfo/python-list