91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

dmidecode收集系統信息

發布時間:2020-07-20 20:45:37 來源:網絡 閱讀:441 作者:1350368559 欄目:開發技術

dmidecode收集系統信息


[root@133 systeminformation]# vim dmidecode_1.py
#!/usr/bin/env python                                                                                                                                                              
                                                                                                                                                                                   
from subprocess import Popen,PIPE                                                                                                                                                  
p = Popen(['dmidecode'],stdout=PIPE)                                                                                                                                               
data=p.stdout                                                                                                                                                                      
line_s = []   #定義一個空列表                                                                                                                                                                  
dmi = {}     #定義一個空字典                                                                                                                                                                      
                                                                                                                                                                                   
a = True              #設置標志位 a = True                                                                                                                                                             
while a:                                                                                                                                                                           
    line = data.readline()                                                                                                                                                         
    if line.startswith('System Information'): #判斷以System Information開頭的段,                                                                                                                              
        while True:                                                                                                                                                                
            line = data.readline()                                                                                                                                                 
            if line == '\n':           #取該段落,直到有空行                                                                                                                                            
                a = False                                                                                                                                                          
                break                                                                                                                                                              
            else:                                                                                                                                                                  
                line_s.append(line)                                                                                                                                                
                                                                                                                                                                                   
                                                                                                                                                                                   
dmi_dic =  dict([i.strip().split(':') for i in line_s])  #把空格和換行符刪除

                                                                                                                          
dmi['Manufacturer'] = dmi_dic['Manufacturer'].strip()  #打印key= Manufacturer的鍵值對                                                                                                                            
print dmi                                                                                                                                                                          
print {'\n'*20}                                                                                                                                                                                                                                                                                                                                                      
                                                                                                                                                                                   
for k,v in dmi_dic.items():   #打印以System Information開頭的段,以key、value打印出來                                                                                                                                                     
    dmi[k] = v.strip()                                                                                                                                                             
print dmi   

[root@133 systeminformation]# python dmidecode_1.py 
{'Manufacturer': 'Dell Inc.'}

set(['\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n'])

{'SKU Number': 'Not Specified', 'UUID': '4C4C4544-0048-4210-8044-B4C04F543258', 'Family': 'Not Specified', 'Serial Number': '4HBDT2X', 'Version': 'Not Specified', 'Product Name': 
'PowerEdge R710', 'Wake-up Type': 'Power Switch', 'Manufacturer': 'Dell Inc.'}


注意:在Python里,以下這些對象相當于布爾值的False
空列表([] )
空元組(() )
空字典({} )
空字符串('' )
零值(0 )
特殊對象None
對象False

[root@133 systeminformation]# cat dmidecode_2.py 
#!/usr/bin/env python
from subprocess import Popen,PIPE

def getDmi():
    p = Popen(['dmidecode'], stdout = PIPE)
    data = p.stdout.read()
    return data

def parseDmi(data):
    lines = []
    line_in = False
    dmi_list = [i for i in data.split('\n') if i]
    for line in dmi_list:
       if line.startswith('System Information'):
           line_in = True
           continue
       if line_in:
           if not line[0].strip():
               lines.append(line)
           else:
               break
    return lines


def dmiDic():
    dmi_dic = {}
    data = getDmi()
    lines = parseDmi(data)
    dic = dict ([i.strip().split(':')for i in lines])
    dmi_dic['vendor'] = dic['Manufacturer']
    return dmi_dic

if __name__ == '__main__':
    print dmiDic()
    
[root@133 systeminformation]# python dmidecode_2.py 
{'vendor': ' Dell Inc.'}


In [1]: a=''  #a的值是null,not a = True

In [2]: not a
Out[2]: True

In [3]: a=' '#a的值是空格或者\t, a!=null, not a = False

In [4]: not a
Out[4]: False

In [5]: a='\t'

In [6]: a
Out[6]: '\t'

In [7]: not a
Out[7]: False

In [8]: a='\t'

In [9]: a
Out[9]: '\t'

In [10]: a.strip()
Out[10]: ''

In [11]: not a.strip()
Out[11]: True



In [12]: a='   '

In [13]: not a
Out[13]: False

In [14]: a.strip()
Out[14]: ''

In [15]: not a.strip()
Out[15]: True


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

静安区| 米泉市| 孟津县| 潜山县| 永川市| 额济纳旗| 格尔木市| 丰都县| 万源市| 南澳县| 莫力| 文水县| 荔浦县| 揭东县| 定陶县| 汤原县| 奉化市| 晋州市| 嘉善县| 崇阳县| 赤壁市| 宣汉县| 南华县| 尉犁县| 西丰县| 徐州市| 永春县| 敦化市| 晋宁县| 襄樊市| 蒙山县| 三明市| 仪征市| 阿勒泰市| 石河子市| 昌都县| 洛阳市| 隆尧县| 贡嘎县| 阿尔山市| 略阳县|