[Bf-python] svg2obj script.

Martin Poirier theeth at yahoo.com
Wed Mar 28 15:24:32 CEST 2007


--- Campbell Barton <cbarton at metavr.com> wrote:

> Hi JMS, can you resolve this?
> 
> 
>   File
> "/root/.blender/scripts/bpymodules/svg2obj.py", line
> 1086, in 
> control_CONTAINT
>      while txt.count(')',t0)>0:
> TypeError: count() takes exactly one argument (2
> given)
> 
> 
> 
> I went through and hada look and found some other
> areas for improvement.
> 
> 
> 		while DATA.find(d,b1,b2)!=-1 :
> 			tagplace.append(DATA.find(d,b1,b2))
> 			b1=DATA.find(d,b1,b2)+1
> 
> # 3 Lookups, not optimal
> 		
> 		while True:
> 			i = DATA.find(d,b1,b2)
> 			if i==-1: break
> 			b1=i+1

You're missing the append call after the break line.

But otherwise, it's obvious that not doing the double
lookup would be faster.

> Also, your using find in a way thats not very
> readable.
> 
> if pathname.find(os.sep)!=-1:
> 
> is better
> 
> if os.sep in pathname:

It's more readable, yes, but actual speed differences
would be barely noticeable (both __contains__, index
and find use the same code in CPython).

> if ndata.find('-')!=-1 and ndata[ndata.find('-')-1]
> not in [' ', ',', 'e']:
> 
> can be
> 
> if '-' in ndata and ndata[ndata.find('-')-1] not in
> ' ,e':

This is still doing a double lookup of '-' on the
string. Best to split it in two.

i = ndata.find('-')
if i != -1 and ndata[i-1] in ' ,e':

Martin


 
____________________________________________________________________________________
The fish are biting. 
Get more visitors on your site using Yahoo! Search Marketing.
http://searchmarketing.yahoo.com/arp/sponsoredsearch_v2.php



More information about the Bf-python mailing list