for循环中的Python列表,我如何将所有内容都放在一个列表中
import os
dir="/tmp/logvol/logs/fil/sap/archive/"
n=os.listdir(dir)
#print n
for x in n:
#print x
l = [];
l.append(os.path.join(dir,x))
print l
输出:
['/tmp/logvol/logs/fil/sap/archive/m.log']
['/tmp/logvol/logs/fil/sap/archive/k.log']
['/tmp/logvol/logs/fil/sap/archive/j.log']
['/tmp/logvol/logs/fil/sap/archive/p.log']
我需要一个列表而不是多个列表。
['/tmp/logvol/logs/fil/sap/archive/m.log', '/tmp/logvol/logs/fil/sap/archive/k.log', '/tmp/logvol/logs/fil/sap/archive/j.log', '/tmp/logvol/logs/fil/sap/archive/p.log']