[Bf-python] svg2obj script.

Campbell Barton cbarton at metavr.com
Wed Mar 28 15:36:20 CEST 2007


Martin Poirier wrote:
> --- 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


Hi Martin, I noticed the missing append just after I sent..

I realize find is the same as "a in b", more of a readability thing.

This syntax is used a lot...
if a.find(foo)>-1:
if a.find(foo)!=1:
if a.find(foo)==1:
vs
if foo in a:
if foo not in a:

and it gets a bit confusing when trying to understand whats going on 
especially in long if statements.

There are other double lookups I ignored for now.

Thanks JMS for the updates too, single tabs are a lot nicer to read.




More information about the Bf-python mailing list