FINAL SOLUTION: ### LOOP OVER DIRECTORY location = '/Users/spyros/Desktop/3NY8MODELSHUMAN/HomologyModels' zdata = [] for filename in os.listdir(location): filename = os.path.join(location, filename) try: zdata.extend(extract_zcoord(filename)) except NameError: print "No such file!" except SyntaxError: print "Check Your Syntax!" except IOError: print "PDB file NOT FOUND!" else: continue
print 'Z-VALUES FOR ALL CHARGED RESIDUES' print zdata #diagnostic ### WRITE Z-COORDINATE LIST TO A BINARY FILE import pickle f1 = open("z_coords1.dat", "wb") pickle.dump(zdata, f1) f1.close() f2 = open("z_coords1.dat", "rb") zdata1 = pickle.load(f2) f2.close() assert zdata == zdata1, "error in pickle/unpickle round trip!" On Wed, May 30, 2012 at 1:09 AM, Steven D'Aprano <st...@pearwood.info>wrote: > Steven D'Aprano wrote: > > location = '/Users/spyros/Desktop/**3NY8MODELSHUMAN/**HomologyModels/' >> zdata = [] >> for filename in os.listdir(location): >> zdata.extend(get_zcoords(**filename)) >> > I only had the filename and not its path, that's why the system was not able to locate the file, so filename = os.path.join(location, filename) was used to solve that. Many thanks to everyone for their time and efforts! Spyros > > > Hah, that can't work. listdir returns the name of the file, but not the > file's path, which means that Python will only look in the current > directory. You need something like this: > > > location = '/Users/spyros/Desktop/**3NY8MODELSHUMAN/**HomologyModels/' > zdata = [] > for filename in os.listdir(location): > zdata.extend(get_zcoords(os.**path.join(location, filename))) > > > Sorry about that. > > > > > -- > Steven > ______________________________**_________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor> >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor