python - Saving Filenames with Condition -


i'm new coding, bare me: i'm trying save names of files fulfill condition. think easiest way make short python program imports , reads files, checks if condition met, , (assuming met) saves names of files.

i have data files 2 columns , 4 rows, this:

 a:    5  b:    5  c:    6  de:    7 

i want save names of files (or part of name of files, if that's simple fix, otherwise can sed file afterwards) of data files have 4th number ([3:1]) greater 8. tried importing files numpy, said couldn't import letters in first column.

another way considering trying command line along lines of cat *.dat >> something.txtbut couldn't figure out how that.

the code i've tried write work is:

import fileinput import glob import numpy np  #filter find value > 8  #globbing value datafiles file_list = glob.glob("/path/to/*.dat")  #creating output file containing f = open('list.txt', 'w')  #looping on files file in file_list:         #for each file in directory, isolating filename         filename = file.split('/')[-1]         #opening files, checking if value greater 8         = np.loadtxt("file", delimiter=' ', usecols=1)         if a[3:0] > 8:                 print >> f,  filename f.close() 

when this, error says typeerror: 'int' object not iterable, don't know that's referring to.

i ended using

import fileinput import glob import numpy np  #filter find value > 8  #globbing datafiles file_list =  glob.glob("/path/to/*.dat")   #creating output file containing  f = open('list.txt', 'w')   #looping on files  file in file_list:         #for each file in directory, isolating filename         filename = file.split('/')[-1]         #opening files, checking if value greater 8         = np.genfromtxt(file)         if a[3,1] > 8:                 f.write(filename + "\n") f.close() 

Comments