[python-win32] How to use data on disk in this generator

Echavarria Gregory, Maria Angelica m.echavarriagregory at umiami.edu
Wed Jan 20 20:22:19 CET 2010


Good afternoon,

I use PythonWin32 in my XP machine. I am programming an application and 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, using 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 python-win32 mailing list