这是我的代码:
import commands
mount = commands.getoutput('mount -v')
lines = mount.splitlines()
points = map(lambda line: line.split()[2], lines)
permission = map(lambda line: line.split()[5], lines)
print points
print permission
我得到的输出是:
['/', '/proc', '/sys', '/dev/pts', '/dev/shm', '/boot', '/proc/sys/fs/binfmt_misc', '/var/lib/nfs/rpc_pipefs']
['(rw)', '(rw)', '(rw)', '(rw,gid=5,mode=620)', '(rw,rootcontext="system_u:object_r:tmpfs_t:s0")', '(rw)', '(rw)', '(rw)']
我想在它前面显示每个分区的权限。像:
'/' (rw)
'/proc' (rw)
等等。怎么办呢?
答案 0 :(得分:1)
你可以使用zip功能
>>> x = [1, 2, 3]
>>> y = [4, 5, 6]
>>> zipped = zip(x, y)
>>> zipped
[(1, 4), (2, 5), (3, 6)]
在你的情况下
zipped = zip(points, permission)
for i, j in zipped:
print i, j
有关详细信息,请查看here