Making code faster
JB
jblazi at hotmail.com
Wed Jul 17 06:06:39 EDT 2002
Bengt Richter wrote:
>>[<string>,<string>]
> - Do you mean that literally? I.e., would
> "['abc','def']\n"
> be a valid example?
> - Why do you have to eval() it? That is probably
> timeconsuming compared to alternatives.
I thought, that would be fast. I can choose the format that
is best. (But probably, I 'd like to have a text format.)
So I could shoose
abc def
too.
> - Are there always two elements in the list?
Yes.
Now I have changed my program to
i = -1
print 'loading file'
def tmp1(s,color=self.sv.lv.newColor):
global i
i += 1
j = string.find(s,' ')
return QSimpleViewItem(i,color,[s[:j],s[j+1:-1]])
try:
myfile = open(filename)
except:
pass
else:
tmp = myfile.readlines()
print 'lines loaded'
myfile.close()
self.sv.lv.rows = map(tmp1,tmp)
self.sv.lv.visible = range(len(self.sv.lv.rows))
print 'lines decoded',self.sv.lv.rows[0].col[0]
This is really faster. I did not undertand, how to get rid
of the global variable <i>, but even if I do not use i at
all and replace it by 0, the time I need is the same.
--
Janos Blazi
-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
http://www.newsfeed.com The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----
More information about the Python-list
mailing list