Returning to this original problem, I have modified my program from a single long procedure to <div>3 functions which do the following: </div><div><br></div><div>serialize_pipeline_model(f): takes as input a file, reads it and parses coordinate values </div>
<div>(numerical entries in the file) into a list</div><div> </div><div>write_to_binary(): writes the generated list to a binary file (pickles it) </div><div><br></div><div>read_binary(): unpickles the aggregate of merged lists that should be one large list. </div>
<div><br></div><div>The code goes like so: </div><div><br></div><div>******</div><div><div>z_coords1 = [] </div></div><div><br></div><div><div>def serialize_pipeline_model(f): </div></div><div> ....</div><div> ..... </div>
<div> # z_coords1 = [] has been declared global</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>global z_coords1 </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>charged_groups = lys_charged_group + arg_charged_group + his_charged_group + asp_charged_group + glu_charged_group </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>for i in range(len(charged_groups)):</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>z_coords1.append(float(charged_groups[i][48:54])) </div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>#print z_coords1 </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>return z_coords1 </div><div><br></div><div><div>import pickle, shelve</div>
<div>print '\nPickling z-coordinates list'</div></div><div><br></div><div><div>def write_to_binary():</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>""" iteratively write successively generated z_coords1 to a binary file """</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>f = open("z_coords1.dat", "ab") </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>pickle.dump(z_coords1, f) </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>f.close() </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>return </div></div><div><br></div><div><div>def read_binary():</div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>""" read the binary list """</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>print '\nUnpickling z-coordinates list' </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>f = open("z_coords1.dat", "rb")</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>z_coords1=pickle.load(f) </div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>print(z_coords1)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>f.close() </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>return </div>
</div><div><br></div><div><div>### LOOP OVER DIRECTORY </div><div>for f in os.listdir('/Users/spyros/Desktop/3NY8MODELSHUMAN/HomologyModels/'):</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>serialize_pipeline_model(f) </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>write_to_binary() </div><div><br></div><div>read_binary() </div><div>print '\n Z-VALUES FOR ALL CHARGED RESIDUES'</div><div>print z_coords1 </div></div>
<div>******</div><div><br></div><div>The problem is that the list (z_coords1) returns as an empty list. I know the code works (too large to post here) </div><div>in a procedural format (z_coords1 can be generated correctly), so as a diagnostic I included a print statement </div>
<div>in the serialize function to see that the list that is generated for each of the 500 files. </div><div><br></div><div>Short of some intricacy with the scopes of the program I may be missing, I am not sure why this is happening? Deos anybody have</div>
<div>any ideas? Many thanks for your time. <br></div><div><br></div><div>Best regards, </div><div>Spyros </div><div><font color="#666666" face="Helvetica Neue, Helvetica, Arial, sans-serif"><span style="line-height:18px"><br>
</span></font></div><div><br><div class="gmail_quote">On Fri, May 18, 2012 at 7:23 PM, Spyros Charonis <span dir="ltr"><<a href="mailto:s.charonis@gmail.com" target="_blank">s.charonis@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear Python community, <div><br></div><div>I have a set of ~500 files which I would like to run a script on. My script extracts certain information and </div>
<div>generates several lists with items I need. For one of these lists, I need to combine the information from all </div>
<div>500 files into one super-list. Is there a way in which I can iteratively execute my script over all 500 files </div><div>and get them to write the list I need into a new file? Many thanks in advance for your time. </div>
<span class="HOEnZb"><font color="#888888">
<div><br></div><div>Spyros </div>
</font></span></blockquote></div><br></div>