unix - Python script to sum values from ls -l output -


from other post read output of ls -l , filter bytes of files in dir. but, want put values list (array) , total sum of elements.

i tried create list b , print sum(b). but, when want create list, memoryerror.

situation now:

import subprocess import csv process = subprocess.popen(['ls', '-l',], stdout=subprocess.pipe) stdout, stderr = process.communicate()  reader = csv.dictreader(stdout.decode('ascii').splitlines(), delimiter = ' ', skipinitialspace=true, fieldnames= ['owner','date','dir','priv','bytes','field2', 'field3', 'field4', 'field5']) 

issues start here

for row in reader:     = row['bytes']     b = [int(a)]     in b:         b.append(i)     continue     print(b) 

output:

traceback (most recent call last):   file "script2.py", line 13, in <module>     b.append(i) memoryerror 

any how put 1 list elements , sum appreciated. thanks!

you iterating on b list , adding elements it, never stop.

for in b:     #b.append(i) #this problem     #continue #go next iteration     print(i) 

edit:

for row in reader:     = row['bytes']     print(a)     b.append(int(a)) 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -