review what i studied `date` - 2017-4-9
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了review what i studied `date` - 2017-4-9相关的知识,希望对你有一定的参考价值。
#!/bin/python #!_*_conding:UTF-8_*_ import os import json r=open(‘url.txt‘,‘r‘).read().split() #读取url.txt文件返回数组 u=open(‘user.txt‘,‘r‘).read().split() devices=[] #定义devices类型为数组list users=[] a = 0 for devpath in r: user = u[a] device = os.path.basename(devpath) #取斜杠后边的值例如 再经过basename 转换后会成为xuhui.com #str devices += [{‘{#SITENAME}‘:device,‘{#user}‘:‘user‘}] #定义数据 #devices的类型从list 变为dict a+=1 print json.dumps({‘data‘:devices},sort_keys=True,indent=7,separators=(‘,‘,‘:‘)) #格式化数据 #sort_keys sort #print devices
Python set 集合
集合内的元素不能重叠
常用集合:
>>> b = set(‘c‘) >>> b.update(‘de‘) ;添加d,e >>> b.add(‘python‘) ;添加python >>> b.add(‘f‘) >>> b.remove(‘python‘) >>> a = set(‘abc‘) >>> b = set(‘cdef‘) >>> a & b ;a和b的交集 set([‘c‘]) >>> a | b set([‘a‘, ‘c‘, ‘b‘, ‘e‘, ‘d‘, ‘f‘]) >>> b -a set([‘e‘, ‘d‘, ‘f‘]) >>> b - a set([‘e‘, ‘d‘, ‘f‘])
Python dict
adict = {key1:value2, key2:value2, …}
>>> a = {"name":"xuhui","address":"haidian"} >>> a {‘name‘: ‘xuhui‘, ‘address‘: ‘haidian‘} >>> type(a) <type ‘dict‘> #有点类似于json #缺点:key是唯一的 >>> a {‘name‘: ‘xuhui‘, ‘address‘: ‘haidian‘} >>> a = {"name":"xuhui","address":"haidian","name":"xuyue"} >>> a {‘name‘: ‘xuyue‘, ‘address‘: ‘haidian‘} #上边的name:xuyue并没有被添加而是替代了key原来的值 >>> a.get(‘name‘) ‘xuyue‘ #查字典 >>> for key in a.keys():print key ... name address #遍历字典键值 >>> for value in a.values():print value ... xuyue haidian #遍历字典的键值的值 >>> for item in a.items():print item ... (‘name‘, ‘xuyue‘) (‘address‘, ‘haidian‘) #遍历字典的项(元素) >>> for key,value in a.items(): print ‘key=%s, value=%s‘ %(key,value) ... key=name, value=xuyue key=address, value=haidian #遍历字典key和value#VMware ESX 运行在裸机上,可以说他是一个操作系统
#用VMware Sphere Client连接的那个
以上是关于review what i studied `date` - 2017-4-9的主要内容,如果未能解决你的问题,请参考以下文章
review what i studied `date` - 2017-4-22
review what i studied `date` - 2017-4-9
review what i studied `date` - 2017-4-11
review what i studied `date` - 2017-4-24