2016-04-06 19 views
0

Guys Python'dan yeni duyuyorum ancak windows 8 bilgisini Python kullanarak almaya çalışıyorum. Ama bunu yapamam, aşağıdaki kodun çıktısını bulamıyorum Ekranlarım yok. Netbeans kullanıyorum. tüm yerleştirmeHerhangi bir çıktı görüntülenemiyor

# To change this license header, choose License Headers in Project Properties. 
# To change this template file, choose Tools | Templates 
# and open the template in the editor. 
if __name__ == "__main__": 

    import os 
    import re 

def sys_info(): 
    values = {} 
    cache = os.popen2("SYSTEMINFO") 
    source = cache[1].read() 
    sysOpts = ["Host Name", "OS Name", "OS Version", "Product ID", "System Manufacturer", "System Model", "System type", "BIOS Version", "Domain", "Windows Directory", "Total Physical Memory", "Available Physical Memory", "Logon Server"] 

    for opt in sysOpts: 
     values[opt] = [item.strip() for item in re.findall("%s:\w*(.*?)\n" % (opt), source, re.IGNORECASE)][0] 
    return values 
    if values == null : 
     print "yep" 
     print (values) 
+0

sys_info tanımlanmış, ancak hiçbir zaman yazdırılmayacak hiçbir şey yoktur – manu190466

cevap

0

İlk import, function ve main sırası bozuk olmadığını.

Burada da, bundan sonra

import os 
import re  

def SysInfo(): 
    values = {} 
    cache = os.popen2("SYSTEMINFO") 
    source = cache[1].read() 
    sysOpts = ["Host Name", "OS Name", "OS Version", "Product ID", "System Manufacturer", "System Model", "System type", "BIOS Version", "Domain", "Windows Directory", "Total Physical Memory", "Available Physical Memory", "Logon Server"] 

    for opt in sysOpts: 
     values[opt] = [item.strip() for item in re.findall("%s:\w*(.*?)\n" % (opt), source, re.IGNORECASE)][0] 
    return values 


if __name__ == "__main__": 
    SysInfo() 

, kod herhangi bir çıktı üreten değildir doğru dizisidir. Ben windows 2010 ve python 2.7. OS version ile ilgisi olup olmadığını merak ediyorum. Ben pencere meraklısı değilim, bu yüzden Cant cevaplayın. Amacınız windows sistem bilgi almak için ise

Ancak, ayrıntılı sistem bilgisi veya bireysel özelliklerini ya almak Sonra aşağıdaki kodu kullanabilirsiniz
pip install wmi

tarafından wmi modülünü yüklemek isteyebilirsiniz.

import wmi 

x = wmi.WMI()  
systeminfo = x.Win32_ComputerSystem()[0] 

print systeminfo 
Manufarturer = systeminfo.Manufacturer 
Model = systeminfo.Model 

print "Manufarturer =", Manufarturer 
print "Model =", Model 

Çıktı: print systeminfo

Manufarturer = Dell Inc. 
Model = Latitude E5430 non-vPro 

ait

içermez ayrıntıları Sen yazdığınız fonksiyon çağırmak zorunda Win32_ComputerSystem class here

0

ilgili bireysel özelliklerini kazmak .

import os 
import re 

if __name__ == "__main__":  
    def sys_info(): 
     values = {} 
     cache = os.popen2("SYSTEMINFO") 
     source = cache[1].read() 
     sysOpts = ["Host Name", "OS Name", "OS Version", "Product ID", "System Manufacturer", "System Model", "System type", "BIOS Version", "Domain", "Windows Directory", "Total Physical Memory", "Available Physical Memory", "Logon Server"] 

     for opt in sysOpts: 
      values[opt] = [item.strip() for item in re.findall("%s:\w*(.*?)\n" % (opt), source, re.IGNORECASE)][0] 
     return values 
     if values == null : 
      print "yep" 
      print (values) 

    # Now call the function here 
    sys_info() 
İlgili konular