I was making a function that recursively searches directories for files with a particular suffixes.
TypeError: slice indices must be integers or None or have an index method
pointing to this line:
if path.endswith('.',sf)==True: l.append(path)
.endswith() returns a boolean and is used to test Strings, why the hell is it giving me issues about non-integers?
also I decided to just print everything and throw in a try/except statement if a file is not a directory or a file(cause that happend pretty quickly into the first run). it ran fine for a minute or two then started spitting out the except clause
something went wrong with /sys/bus/cpu/devices/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu1/node0/cpu0/node0/cpu1/subsystem/devices/cpu0/node0/cpu0/subsystem/devices/cpu0/subsystem/devices/cpu0/subsystem something went wrong with /sys/bus/cpu/devices/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu1/node0/cpu0/node0/cpu1/subsystem/devices/cpu0/node0/cpu0/subsystem/devices/cpu0/subsystem/devices/cpu0 something went wrong with /sys/bus/cpu/devices/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu0/node0/cpu1/node0/cpu0/node0/cpu1/subsystem/devices/cpu0/node0/cpu0/subsystem/devices/cpu0/subsystem/devices/cpu1/cache/power
well I just Ctrl-Z’d went back into ipython3 and tried again, which immediately brought up the same message, even though the specified directory was / . why did it start back at this same area?
edit: code
def recursive_search(dr, sf):
"""searches every potential path from parent directory for files with the matching suffix"""
l=[]#for all the good little scripts and files with the right last name
for name in os.listdir(dr):#for every item in directory
path=os.path.join(dr, name)#path is now path/to/item
if os.path.isfile(path):
if path.endswith('.',sf)==True:
l.append(path)
else:
#try:
recursive_search(path, sf)
#except:
#print ('something went wrong with ', path)
if it comes out looking weird I'm having some trouble with the formatting.