module import performance question

Peter Abel PeterAbel at
Tue Nov 11 23:19:39 CET 2003

jeff at (Jeff Sykes) wrote in message news:<729b56c7.0311102210.4869d4f6 at>...

> Here is a code snip:
> dyn_blocks = {}  # set up a dict of the dynamic imports
> if confok:  # was the configuration present?
>   blocks = getBlocks(config)  # get the application info from config
>   for block in blocks:  # each block indictates the ap & pg (module)

doen't know how long is len(blocks), if it's very long you could
accelerate the *for loop* be replacing the following two lines with:

      (ap,pg) = string.split(string.strip(block[1:]))
**Remark: block[1:len(block)] is the same as block[1:], but without
          calulating len(block) everytime, further more the split
          and the strip is done only once

>     ap = string.split(string.strip(block[1:len(block)]))[0]
>     pg = string.split(string.strip(block[1:len(block)]))[1]



More information about the Python-list mailing list