Making code faster
Armin Steinhoff
a-steinhoff at web.de
Wed Jul 17 07:05:19 EDT 2002
JB <jblazi at hotmail.com> wrote in message news:<3d3445f9_7 at news.newsgroups.com>...
> How can I make the following code faster? I open a (text)
> file and read the lines in the file. The lines of the file
> have the form
>
> [<string>,<string>]
>
> After the lines have been loaded, I set up a new list via
> the function tmp1.
>
> i = -1
> print 'loading file'
> def tmp1(s):
> global i
> i += 1
> return QSimpleViewItem(i,self.sv.lv.newColor,eval(s))
>
> try:
> myfile = open(filename)
> except:
> pass
> else:
> tmp = myfile.readlines()
> print 'lines loaded'
> datei.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]
>
> Any ideas? It is astonishing that loading the lines
... how man lines? How long are the lines?
> from
external storage takes much less time than the mapping
> itself!
Have you considered to use Pyrex in order to convert it into a C module??
Armin
More information about the Python-list
mailing list