我想計算各種文件的大小的總和。這是我的腳本:腳本文件大小的總和
import os
date = raw_input('Enter date in format YYYYMMDD ')
file1 = 'p_poupe_' + date + '.tar.gz.done'
file2 = 'p_poupw_' + date + '.tar.gz.done'
file3 = 'p_pojk_' + date + '.tar.gz.done'
a1 = os.system('zcat ' + file1 + '|wc --bytes')
a2 = os.system('zcat ' + file2 + '|wc --bytes')
a3 = os.system('zcat ' + file3 + '|wc --bytes')
print a1,a2,a3
sum = a1 + a2 + a3
print sum
但值不存儲在變量中。任何人都可以告訴我我做錯了什麼。我怎樣才能修改腳本,以便將值存儲在變量中而不是作爲輸出。
'操作系統。system'將返回'wc'的返回碼,而不是輸出到'stdout' – 2015-03-13 12:37:06
可能重複[在Python中os.system()的返回值是什麼?](http://stackoverflow.com/questions/ 6466711/os-system-in-python中的什麼是返回值) – 2015-03-13 12:38:44
[os.path.getsize](https://docs.python.org/2/library/os.path.html #os.path.getsize)應該完成工作...''os.system'返回值不是創建進程的標準輸出。 – 2015-03-13 12:42:13