Quick reminder of how to split a "ls -l" listing. It is problematic because the last field which is the directory or file name can have spaces itself, so splitting on spaces which is the only option here still need a bit of additional work.
import config import subprocess ## First experiment doing manual manipulation of the fields. ## Basically split on all spaces and then assemble the file name. def dir_listing(): ls_lines = subprocess.check_output(['ls', '-l']).splitlines() ls_arr=  for item in ls_lines: if not "total" in item: f = item.split() ## fname = item.join(str(v) for v in item.index if v > 7) fname = "" for idx,val in enumerate(f): if idx > 7: fname = fname + str(val) + " " fname = fname[:-1] ls_fields = [f,f,f,f,f,f+"-"+f+"-"+f,fname] ls_arr.append(ls_fields) return ls_arr ## Second attempt is split on spaces with a max split defined. ## This sounds like the obvious way to do this but I needed to use "None" and not " " ## as shown below. def dir_listing_optimized(): ls_lines = subprocess.check_output(['ls', '-l']).splitlines() ls_arr=  for item in ls_lines: if not "total" in item: ## None will use arbitrary strings of whitespace characters (space, tab, newline, return, formfeed) ## When using split(" ",8) I had more separation than I expected and therefor my last field ## was not working right. f = item.split(None,8) ls_arr.append(f) return ls_arr for dir in dir_listing(): print dir for dir in dir_listing_optimized(): print dir