[Qgis-developer] How to use data on disk in this generator

Echavarria Gregory, Maria Angelica m.echavarriagregory at umiami.edu
Wed Jan 20 13:04:27 EST 2010


Good afternoon All,

I use Python 2.5.4 along with OSGeo4W and win32 OS. I am programming a QGIS application but have no trouble with that part right now. I'm posting to you guys because you are very smart and wouldn't mind a small challenge... help is welcome, please.

I have trouble with memory when using the sumComb list below, that has a size of 2,657,205 elements. I DO NEED this many elements because they are product of combinatorial math operations. To solve my memory problem I created a file on disk that stores the elements of the list as they are created. Now, I need to use the 'list' in a generator and have not been able to replicate the effect without actually calling/storing the list in memory, that is, I need to use the data directly from the file on disk:

I need to mimic what the following generator does:

def  validList(sumComb, GammaPossible, valid):
    for l in sumComb:
       for m in sumComb:
         for n in sumComb:
                k = [l,m,n]
                i = 0
                while i < valid:
                     C = 0
                     j = 0
                     while j < 3:
                           C = C +((GammaPossible[i][j])*k[j])
                           j += 1
                     yield C
                     i += 1

By not using the list sumComb in memory, but having its elements in a file F writen using F = open("my_list.txt", "w") and where elements are stored with column "/n" separation. I have not been able to find the appropriate syntax for the nested 'for' loops to replace sumComb list by using F.readlines(), str.split(), etc.  Please help me with this little challenge.

Angelica.


More information about the Qgis-developer mailing list