这是我的代码:
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)
等等。怎么能做到?
最佳答案
你可以使用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
关于python - 在python中格式化输出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15331604/