【发布时间】:2014-11-25 15:58:56
【问题描述】:
我需要对pysphere'sVIServer.get_datastore 返回的字典进行排序。它应该按我们可以获得的数据存储上的可用空间进行排序:
from pysphere import VIServer, VIProperty
if __name__ == "__main__":
server = VIServer()
print "Connecting to vSphere..."
server.connect(VSPHERE_IP, VSPHERE_USER, VSPHERE_PASS)
datastores = server.get_datastores()
for ds, name in datastores.iteritems():
props = VIProperty(server, ds)
freeSpace = props.summary.freeSpace
我知道我可以使用sorted(iterable[, cmp[, key[, reverse]]]) 并创建一个自定义排序函数,但我不知道该函数的参数是哪种类型。
我不能使用OrderedDict,因为我绑定到python 2.6(不要问为什么:()
【问题讨论】:
标签: python sorting dictionary python-2.6