Extract all GPU name, model and GPU ram Announcing the arrival of Valued Associate #679: Cesar...

The logistics of corpse disposal

Is it fair for a professor to grade us on the possession of past papers?

Fundamental Solution of the Pell Equation

Apollo command module space walk?

English words in a non-english sci-fi novel

porting install scripts : can rpm replace apt?

How to call a function with default parameter through a pointer to function that is the return of another function?

How do I stop a creek from eroding my steep embankment?

What causes the vertical darker bands in my photo?

How do pianists reach extremely loud dynamics?

Why are there no cargo aircraft with "flying wing" design?

Can an alien society believe that their star system is the universe?

Book where humans were engineered with genes from animal species to survive hostile planets

Why did the rest of the Eastern Bloc not invade Yugoslavia?

Seeking colloquialism for “just because”

How does the particle を relate to the verb 行く in the structure「A を + B に行く」?

51k Euros annually for a family of 4 in Berlin: Is it enough?

Storing hydrofluoric acid before the invention of plastics

Is the Standard Deduction better than Itemized when both are the same amount?

How to find all the available tools in mac terminal?

Can I cast Passwall to drop an enemy into a 20-foot pit?

Denied boarding although I have proper visa and documentation. To whom should I make a complaint?

When were vectors invented?

Do I really need recursive chmod to restrict access to a folder?



Extract all GPU name, model and GPU ram



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Calculating sum of primes using the CPU and GPUregex to extract version infoExtract Pages from PDF based on search in pythonExtract entities from sentencesAgent-based model performance issue with list comprehensionOptimize GPU usage for real-time object detection from camera with TensorFlow GPU and OpenCVExtract and sort all numbers that appear after ',Extract name, address and phone number from some web pages using multiprocessingRandom name generator from JSON fileHackerrank All Women's Codesprint 2019: Name the Product





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







5












$begingroup$


I currently use this code to extract the required GPU data. Can you review this method for efficiency or best coding practices?



Code



import wmi 
c = wmi.WMI()
def gpu_check():
gpu_ouy =["fu","7"]
gpu_a =""
gpu_b =""
ass = str(c.Win32_VideoController()[0])
asss = str(c.Win32_VideoController()[1])
aq = ass.split()
for x in range(len(c.Win32_VideoController())):
ass = str(c.Win32_VideoController()[x])
saa = ass.split()
saa.remove("instance")
saa.remove("of")
saa.remove("Win32_VideoController")
saa.remove("{")
saa.remove("AdapterCompatibility")
saa.remove("AdapterDACType")
while "=" in saa:
saa.remove("=")
saa.remove("};")
saa.remove("SystemName")
saa.remove("Description")
saa.remove("InstalledDisplayDrivers")
saa.remove("DeviceID")
saa.remove("DriverDate")
saa.remove("Name")
saa.remove("Status")
saa.remove("Caption")
saa.remove("InfFilename")
saa.remove("ConfigManagerUserConfig")
saa.remove("ConfigManagerErrorCode")
saa.remove("InfSection")
saa.remove("DriverVersion")
if "CurrentScanMode" in saa:
saa.remove("CurrentScanMode")
saa.remove("SystemCreationClassName")
saa.remove("CreationClassName")
if "CurrentRefreshRate" in saa:
saa.remove("CurrentRefreshRate")
if "CurrentHorizontalResolution" in saa:
saa.remove("CurrentHorizontalResolution")
if "CurrentVerticalResolution" in saa:
saa.remove("CurrentVerticalResolution")
if "CurrentNumberOfColors" in saa:
saa.remove("CurrentNumberOfColors")
if "MinRefreshRate" in saa:
saa.remove("MinRefreshRate")
if 'colors";' in saa:
saa.remove('colors";')
if "CurrentBitsPerPixel" in saa:
saa.remove("CurrentBitsPerPixel")
if "MaxRefreshRate" in saa:
saa.remove("MaxRefreshRate")
saa.remove("VideoProcessor")
saa.remove("PNPDeviceID")
if "CurrentNumberOfColumns" in saa:
saa.remove("CurrentNumberOfColumns")
if "CurrentNumberOfRows" in saa:
saa.remove("CurrentNumberOfRows")
saa.remove("Monochrome")
saa.remove("Availability")
del saa[5]
if '"Integrated' in saa:
saa.remove('"Integrated')
if '"Internal";' in saa:
saa.remove('"Internal";')
if 'VideoModeDescription' in saa:
saa.remove('VideoModeDescription')
saa.remove('AdapterRAM')
if 'RAMDAC";' in saa:
saa.remove('RAMDAC";')
sqa =int(((int(str(saa[1]).replace(";",""))/1024)/1024)/1000)
saa[1] = sqa
else:
sqa =int(((int(str(saa[2]).replace(";",""))/1024)/1024)/1000)
saa[2] = sqa
if 'Corporation";' in saa:
saa.remove('Corporation";')
while "FALSE;" in saa:
saa.remove("FALSE;")
gpu_a =""
gpu_b =""
if saa[6] =="0;":
gpu_a = str(saa[2]).replace('"',"")+" "+saa[3]+" "+saa[4]+" "+str(saa[5]).replace('";',"")+" "+str(saa[1])+" GB"
gpu_ouy[0] = str(gpu_a)
else:
gpu_b = str(saa[2]).replace('"',"")+" "+saa[3]+" "+saa[4]+" "+str(saa[5]).replace('";',"")+" "+str(saa[6]).replace('";',"")+" "+str(saa[1])+" GB"
gpu_ouy[1] = gpu_b
return gpu_ouy









share|improve this question









New contributor




tadas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$












  • $begingroup$
    What is c? Is c.Win32_VideoController() a simple accessor?
    $endgroup$
    – greybeard
    21 hours ago






  • 2




    $begingroup$
    Welcome to Code Review. Do not comment comments asking for clarification: Edit your question, the code in it unless reviews have started.
    $endgroup$
    – greybeard
    21 hours ago






  • 8




    $begingroup$
    ass is a very bad variable name.
    $endgroup$
    – 422_unprocessable_entity
    18 hours ago






  • 9




    $begingroup$
    ass.split() is an even worse statement.
    $endgroup$
    – Raimund Krämer
    13 hours ago


















5












$begingroup$


I currently use this code to extract the required GPU data. Can you review this method for efficiency or best coding practices?



Code



import wmi 
c = wmi.WMI()
def gpu_check():
gpu_ouy =["fu","7"]
gpu_a =""
gpu_b =""
ass = str(c.Win32_VideoController()[0])
asss = str(c.Win32_VideoController()[1])
aq = ass.split()
for x in range(len(c.Win32_VideoController())):
ass = str(c.Win32_VideoController()[x])
saa = ass.split()
saa.remove("instance")
saa.remove("of")
saa.remove("Win32_VideoController")
saa.remove("{")
saa.remove("AdapterCompatibility")
saa.remove("AdapterDACType")
while "=" in saa:
saa.remove("=")
saa.remove("};")
saa.remove("SystemName")
saa.remove("Description")
saa.remove("InstalledDisplayDrivers")
saa.remove("DeviceID")
saa.remove("DriverDate")
saa.remove("Name")
saa.remove("Status")
saa.remove("Caption")
saa.remove("InfFilename")
saa.remove("ConfigManagerUserConfig")
saa.remove("ConfigManagerErrorCode")
saa.remove("InfSection")
saa.remove("DriverVersion")
if "CurrentScanMode" in saa:
saa.remove("CurrentScanMode")
saa.remove("SystemCreationClassName")
saa.remove("CreationClassName")
if "CurrentRefreshRate" in saa:
saa.remove("CurrentRefreshRate")
if "CurrentHorizontalResolution" in saa:
saa.remove("CurrentHorizontalResolution")
if "CurrentVerticalResolution" in saa:
saa.remove("CurrentVerticalResolution")
if "CurrentNumberOfColors" in saa:
saa.remove("CurrentNumberOfColors")
if "MinRefreshRate" in saa:
saa.remove("MinRefreshRate")
if 'colors";' in saa:
saa.remove('colors";')
if "CurrentBitsPerPixel" in saa:
saa.remove("CurrentBitsPerPixel")
if "MaxRefreshRate" in saa:
saa.remove("MaxRefreshRate")
saa.remove("VideoProcessor")
saa.remove("PNPDeviceID")
if "CurrentNumberOfColumns" in saa:
saa.remove("CurrentNumberOfColumns")
if "CurrentNumberOfRows" in saa:
saa.remove("CurrentNumberOfRows")
saa.remove("Monochrome")
saa.remove("Availability")
del saa[5]
if '"Integrated' in saa:
saa.remove('"Integrated')
if '"Internal";' in saa:
saa.remove('"Internal";')
if 'VideoModeDescription' in saa:
saa.remove('VideoModeDescription')
saa.remove('AdapterRAM')
if 'RAMDAC";' in saa:
saa.remove('RAMDAC";')
sqa =int(((int(str(saa[1]).replace(";",""))/1024)/1024)/1000)
saa[1] = sqa
else:
sqa =int(((int(str(saa[2]).replace(";",""))/1024)/1024)/1000)
saa[2] = sqa
if 'Corporation";' in saa:
saa.remove('Corporation";')
while "FALSE;" in saa:
saa.remove("FALSE;")
gpu_a =""
gpu_b =""
if saa[6] =="0;":
gpu_a = str(saa[2]).replace('"',"")+" "+saa[3]+" "+saa[4]+" "+str(saa[5]).replace('";',"")+" "+str(saa[1])+" GB"
gpu_ouy[0] = str(gpu_a)
else:
gpu_b = str(saa[2]).replace('"',"")+" "+saa[3]+" "+saa[4]+" "+str(saa[5]).replace('";',"")+" "+str(saa[6]).replace('";',"")+" "+str(saa[1])+" GB"
gpu_ouy[1] = gpu_b
return gpu_ouy









share|improve this question









New contributor




tadas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$












  • $begingroup$
    What is c? Is c.Win32_VideoController() a simple accessor?
    $endgroup$
    – greybeard
    21 hours ago






  • 2




    $begingroup$
    Welcome to Code Review. Do not comment comments asking for clarification: Edit your question, the code in it unless reviews have started.
    $endgroup$
    – greybeard
    21 hours ago






  • 8




    $begingroup$
    ass is a very bad variable name.
    $endgroup$
    – 422_unprocessable_entity
    18 hours ago






  • 9




    $begingroup$
    ass.split() is an even worse statement.
    $endgroup$
    – Raimund Krämer
    13 hours ago














5












5








5





$begingroup$


I currently use this code to extract the required GPU data. Can you review this method for efficiency or best coding practices?



Code



import wmi 
c = wmi.WMI()
def gpu_check():
gpu_ouy =["fu","7"]
gpu_a =""
gpu_b =""
ass = str(c.Win32_VideoController()[0])
asss = str(c.Win32_VideoController()[1])
aq = ass.split()
for x in range(len(c.Win32_VideoController())):
ass = str(c.Win32_VideoController()[x])
saa = ass.split()
saa.remove("instance")
saa.remove("of")
saa.remove("Win32_VideoController")
saa.remove("{")
saa.remove("AdapterCompatibility")
saa.remove("AdapterDACType")
while "=" in saa:
saa.remove("=")
saa.remove("};")
saa.remove("SystemName")
saa.remove("Description")
saa.remove("InstalledDisplayDrivers")
saa.remove("DeviceID")
saa.remove("DriverDate")
saa.remove("Name")
saa.remove("Status")
saa.remove("Caption")
saa.remove("InfFilename")
saa.remove("ConfigManagerUserConfig")
saa.remove("ConfigManagerErrorCode")
saa.remove("InfSection")
saa.remove("DriverVersion")
if "CurrentScanMode" in saa:
saa.remove("CurrentScanMode")
saa.remove("SystemCreationClassName")
saa.remove("CreationClassName")
if "CurrentRefreshRate" in saa:
saa.remove("CurrentRefreshRate")
if "CurrentHorizontalResolution" in saa:
saa.remove("CurrentHorizontalResolution")
if "CurrentVerticalResolution" in saa:
saa.remove("CurrentVerticalResolution")
if "CurrentNumberOfColors" in saa:
saa.remove("CurrentNumberOfColors")
if "MinRefreshRate" in saa:
saa.remove("MinRefreshRate")
if 'colors";' in saa:
saa.remove('colors";')
if "CurrentBitsPerPixel" in saa:
saa.remove("CurrentBitsPerPixel")
if "MaxRefreshRate" in saa:
saa.remove("MaxRefreshRate")
saa.remove("VideoProcessor")
saa.remove("PNPDeviceID")
if "CurrentNumberOfColumns" in saa:
saa.remove("CurrentNumberOfColumns")
if "CurrentNumberOfRows" in saa:
saa.remove("CurrentNumberOfRows")
saa.remove("Monochrome")
saa.remove("Availability")
del saa[5]
if '"Integrated' in saa:
saa.remove('"Integrated')
if '"Internal";' in saa:
saa.remove('"Internal";')
if 'VideoModeDescription' in saa:
saa.remove('VideoModeDescription')
saa.remove('AdapterRAM')
if 'RAMDAC";' in saa:
saa.remove('RAMDAC";')
sqa =int(((int(str(saa[1]).replace(";",""))/1024)/1024)/1000)
saa[1] = sqa
else:
sqa =int(((int(str(saa[2]).replace(";",""))/1024)/1024)/1000)
saa[2] = sqa
if 'Corporation";' in saa:
saa.remove('Corporation";')
while "FALSE;" in saa:
saa.remove("FALSE;")
gpu_a =""
gpu_b =""
if saa[6] =="0;":
gpu_a = str(saa[2]).replace('"',"")+" "+saa[3]+" "+saa[4]+" "+str(saa[5]).replace('";',"")+" "+str(saa[1])+" GB"
gpu_ouy[0] = str(gpu_a)
else:
gpu_b = str(saa[2]).replace('"',"")+" "+saa[3]+" "+saa[4]+" "+str(saa[5]).replace('";',"")+" "+str(saa[6]).replace('";',"")+" "+str(saa[1])+" GB"
gpu_ouy[1] = gpu_b
return gpu_ouy









share|improve this question









New contributor




tadas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$




I currently use this code to extract the required GPU data. Can you review this method for efficiency or best coding practices?



Code



import wmi 
c = wmi.WMI()
def gpu_check():
gpu_ouy =["fu","7"]
gpu_a =""
gpu_b =""
ass = str(c.Win32_VideoController()[0])
asss = str(c.Win32_VideoController()[1])
aq = ass.split()
for x in range(len(c.Win32_VideoController())):
ass = str(c.Win32_VideoController()[x])
saa = ass.split()
saa.remove("instance")
saa.remove("of")
saa.remove("Win32_VideoController")
saa.remove("{")
saa.remove("AdapterCompatibility")
saa.remove("AdapterDACType")
while "=" in saa:
saa.remove("=")
saa.remove("};")
saa.remove("SystemName")
saa.remove("Description")
saa.remove("InstalledDisplayDrivers")
saa.remove("DeviceID")
saa.remove("DriverDate")
saa.remove("Name")
saa.remove("Status")
saa.remove("Caption")
saa.remove("InfFilename")
saa.remove("ConfigManagerUserConfig")
saa.remove("ConfigManagerErrorCode")
saa.remove("InfSection")
saa.remove("DriverVersion")
if "CurrentScanMode" in saa:
saa.remove("CurrentScanMode")
saa.remove("SystemCreationClassName")
saa.remove("CreationClassName")
if "CurrentRefreshRate" in saa:
saa.remove("CurrentRefreshRate")
if "CurrentHorizontalResolution" in saa:
saa.remove("CurrentHorizontalResolution")
if "CurrentVerticalResolution" in saa:
saa.remove("CurrentVerticalResolution")
if "CurrentNumberOfColors" in saa:
saa.remove("CurrentNumberOfColors")
if "MinRefreshRate" in saa:
saa.remove("MinRefreshRate")
if 'colors";' in saa:
saa.remove('colors";')
if "CurrentBitsPerPixel" in saa:
saa.remove("CurrentBitsPerPixel")
if "MaxRefreshRate" in saa:
saa.remove("MaxRefreshRate")
saa.remove("VideoProcessor")
saa.remove("PNPDeviceID")
if "CurrentNumberOfColumns" in saa:
saa.remove("CurrentNumberOfColumns")
if "CurrentNumberOfRows" in saa:
saa.remove("CurrentNumberOfRows")
saa.remove("Monochrome")
saa.remove("Availability")
del saa[5]
if '"Integrated' in saa:
saa.remove('"Integrated')
if '"Internal";' in saa:
saa.remove('"Internal";')
if 'VideoModeDescription' in saa:
saa.remove('VideoModeDescription')
saa.remove('AdapterRAM')
if 'RAMDAC";' in saa:
saa.remove('RAMDAC";')
sqa =int(((int(str(saa[1]).replace(";",""))/1024)/1024)/1000)
saa[1] = sqa
else:
sqa =int(((int(str(saa[2]).replace(";",""))/1024)/1024)/1000)
saa[2] = sqa
if 'Corporation";' in saa:
saa.remove('Corporation";')
while "FALSE;" in saa:
saa.remove("FALSE;")
gpu_a =""
gpu_b =""
if saa[6] =="0;":
gpu_a = str(saa[2]).replace('"',"")+" "+saa[3]+" "+saa[4]+" "+str(saa[5]).replace('";',"")+" "+str(saa[1])+" GB"
gpu_ouy[0] = str(gpu_a)
else:
gpu_b = str(saa[2]).replace('"',"")+" "+saa[3]+" "+saa[4]+" "+str(saa[5]).replace('";',"")+" "+str(saa[6]).replace('";',"")+" "+str(saa[1])+" GB"
gpu_ouy[1] = gpu_b
return gpu_ouy






python performance python-3.x






share|improve this question









New contributor




tadas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




tadas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 21 hours ago







tadas













New contributor




tadas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 22 hours ago









tadastadas

286




286




New contributor




tadas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





tadas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






tadas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • $begingroup$
    What is c? Is c.Win32_VideoController() a simple accessor?
    $endgroup$
    – greybeard
    21 hours ago






  • 2




    $begingroup$
    Welcome to Code Review. Do not comment comments asking for clarification: Edit your question, the code in it unless reviews have started.
    $endgroup$
    – greybeard
    21 hours ago






  • 8




    $begingroup$
    ass is a very bad variable name.
    $endgroup$
    – 422_unprocessable_entity
    18 hours ago






  • 9




    $begingroup$
    ass.split() is an even worse statement.
    $endgroup$
    – Raimund Krämer
    13 hours ago


















  • $begingroup$
    What is c? Is c.Win32_VideoController() a simple accessor?
    $endgroup$
    – greybeard
    21 hours ago






  • 2




    $begingroup$
    Welcome to Code Review. Do not comment comments asking for clarification: Edit your question, the code in it unless reviews have started.
    $endgroup$
    – greybeard
    21 hours ago






  • 8




    $begingroup$
    ass is a very bad variable name.
    $endgroup$
    – 422_unprocessable_entity
    18 hours ago






  • 9




    $begingroup$
    ass.split() is an even worse statement.
    $endgroup$
    – Raimund Krämer
    13 hours ago
















$begingroup$
What is c? Is c.Win32_VideoController() a simple accessor?
$endgroup$
– greybeard
21 hours ago




$begingroup$
What is c? Is c.Win32_VideoController() a simple accessor?
$endgroup$
– greybeard
21 hours ago




2




2




$begingroup$
Welcome to Code Review. Do not comment comments asking for clarification: Edit your question, the code in it unless reviews have started.
$endgroup$
– greybeard
21 hours ago




$begingroup$
Welcome to Code Review. Do not comment comments asking for clarification: Edit your question, the code in it unless reviews have started.
$endgroup$
– greybeard
21 hours ago




8




8




$begingroup$
ass is a very bad variable name.
$endgroup$
– 422_unprocessable_entity
18 hours ago




$begingroup$
ass is a very bad variable name.
$endgroup$
– 422_unprocessable_entity
18 hours ago




9




9




$begingroup$
ass.split() is an even worse statement.
$endgroup$
– Raimund Krämer
13 hours ago




$begingroup$
ass.split() is an even worse statement.
$endgroup$
– Raimund Krämer
13 hours ago










3 Answers
3






active

oldest

votes


















8












$begingroup$

I fully agree with the answer by @BaileyParker. I have basically no idea what any of your variables are. Or what your code is actually supposed to achieve. And indeed, there is probably a better way to achieve what you want in this case. However, knowing how to do string and list parsing efficiently is also sometimes necessary, so this is how you could have done that better.



In your code, most of the lines are spent on removing unneeded strings from a list. Instead of manually removing each one of them (and even adding guards for the ones you know might not even exist in the list, hoping you don't miss any of those), just define a blacklist of terms you never want in your list and exclude them. If you choose a set as a data structure for that blacklist, you only need to iterate once over your list and checking if each element is in the blacklist is $mathcal{O}(1)$, making this algorithm $mathcal{O}(n)$.



Your code on the other hand is $mathcal{O}(n)$ for every single term you remove, because the whole list needs to be checked for the item in the worst case, and twice that if you first check if a term exists in the list with in, which is also $mathcal{O}(n)$. This makes your code $mathcal{O}(nk)$ with $n$ the list of methods and $k$ the number of terms you want removed.



blacklist = {"instance", "of", ...}

for methods in c.Win32_VideoController():
methods = [m for m in str(methods).split() if m not in blacklist]
# do something with it





share|improve this answer











$endgroup$





















    20












    $begingroup$

    Let's ignore efficiency. It took me five minutes to figure out what you were trying to do. In the kindest way possible, this is a mess. But let's fix that!



    Your variable names are terrible. I have no idea what an ass is. What about an asss? Surely that's a bad idea, because it's very easy to mistake one for the other. Even if it wasn't, what are they? A variable name should describe what it holds. A bunch of random characters aren't helpful. Same goes for gpu_ouy. Is that a typo? What are gpu_a and gpu_b? What is aq? What is c? What is saa? None of these variables names help someone reading your code understand their function.



    Don't use len in a for loop. The idiomatic python approach is to just iterate over the collection (and let it deal with lengths and indices). So instead of:



    for x in range(len(c.Win32_VideoController())):
    ass = str(c.Win32_VideoController()[x])


    Use this:



    for controller in c.Win32_VideoController():
    # do something with controller...
    pass


    Some random points before we get to the big issue:




    • In sqa =int(((int(str(saa[1]).replace(";",""))/1024)/1024)/1000), use // instead of calling int so much. This does floor division. So int(int(x / 1024) / 1024) is the same as x // 1024 // 1024. But then you could just merge them: x // (1024 * 1024). But what are those numbers? I suspect you're converting from bytes to GB (expect 1000 MB = 1 GB isn't correct unless you're dealing with harddrives, which sometimes define the measurements like so). So instead use a constant: BYTES_PER_GB = 1024 * 1024 * 1000. Then do: int(vram_size_bytes) // BYTES_PER_GB.

    • Fix your spacing and formatting. PEP8 your code!

    • What is saa[1] above? You have some many magic indices that no one can discern without understanding the value of str(controller). Prefer giving things descriptive names (use variables, heck overuse variables to make things clear) to magic indices.


    • remove can fail (it raises a ValueError if the element isn't found in the list).

    • You don't need to initialize gpu_a and gpu_b (ex. gpu_a = "" is unnecessary), because later you assign stuff to them. They will be initialized on first assignment.


    But now the largest issue: you're doing a ton of extra work that you almost certainly don't have to do! I can't seem to find good docs for wmi's wrapping around this, but according to the microsoft docs, this probably returns an object of some type. That means instead of all of this convoluted and fragile string parsing you're attempting, you can probably get at the information you want by just doing controller.AdapterRAM // BYTES_PER_GB or controller.Description (where controller comes from for controller in wmi.WMI().Win32_VideoController()). Open up a Python REPL by running python3 and then run the following:



    >>> import wmi
    >>> controller = wmi.WMI().Win32_VideoController()[0]
    >>> help(controller)
    >>> dir(controller)


    That should give you an idea of all of the information you can get from it. You don't need to be doing all that string parsing! The information is already available on properties of the object!






    share|improve this answer









    $endgroup$













    • $begingroup$
      Strictly speaking, one GB is 1000 MB and one MB is 1000 KB, but one GiB is 1024 MiB and one MiB is 1024 KiB. Going by the standards as defined by the IEC, that is.
      $endgroup$
      – vurp0
      3 hours ago



















    2












    $begingroup$

    To add on to what @BaileyParker said, instead of phrasing the WMI string directly, you should use the wmi_property command to get the value of the property you are interested in. You can get a list of properties from the Microsoft documentation: Win32_VideoController



    For example, you could do something like this:



    import json
    import wmi

    controllers = wmi.WMI().Win32_VideoController()

    gpu_data = list()

    for controller in controllers:
    controller_info = {
    'Name': controller.wmi_property('Name').value,
    'HRes': controller.wmi_property('CurrentHorizontalResolution').value,
    'VRes': controller.wmi_property('CurrentVerticalResolution').value,
    }
    gpu_data.append(controller_info)

    print json.dumps(gpu_data, indent=4)


    On my machine it prints the output:



    [
    {
    "VRes": 1080,
    "Name": "NVIDIA GeForce GTX 1050",
    "HRes": 1920
    }
    ]





    share|improve this answer











    $endgroup$













    • $begingroup$
      I would make that for loop a list comprehension. Otherwise this seems to be the solution the OP actually needs in this case.
      $endgroup$
      – Graipher
      9 hours ago












    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "196"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });






    tadas is a new contributor. Be nice, and check out our Code of Conduct.










    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217532%2fextract-all-gpu-name-model-and-gpu-ram%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    8












    $begingroup$

    I fully agree with the answer by @BaileyParker. I have basically no idea what any of your variables are. Or what your code is actually supposed to achieve. And indeed, there is probably a better way to achieve what you want in this case. However, knowing how to do string and list parsing efficiently is also sometimes necessary, so this is how you could have done that better.



    In your code, most of the lines are spent on removing unneeded strings from a list. Instead of manually removing each one of them (and even adding guards for the ones you know might not even exist in the list, hoping you don't miss any of those), just define a blacklist of terms you never want in your list and exclude them. If you choose a set as a data structure for that blacklist, you only need to iterate once over your list and checking if each element is in the blacklist is $mathcal{O}(1)$, making this algorithm $mathcal{O}(n)$.



    Your code on the other hand is $mathcal{O}(n)$ for every single term you remove, because the whole list needs to be checked for the item in the worst case, and twice that if you first check if a term exists in the list with in, which is also $mathcal{O}(n)$. This makes your code $mathcal{O}(nk)$ with $n$ the list of methods and $k$ the number of terms you want removed.



    blacklist = {"instance", "of", ...}

    for methods in c.Win32_VideoController():
    methods = [m for m in str(methods).split() if m not in blacklist]
    # do something with it





    share|improve this answer











    $endgroup$


















      8












      $begingroup$

      I fully agree with the answer by @BaileyParker. I have basically no idea what any of your variables are. Or what your code is actually supposed to achieve. And indeed, there is probably a better way to achieve what you want in this case. However, knowing how to do string and list parsing efficiently is also sometimes necessary, so this is how you could have done that better.



      In your code, most of the lines are spent on removing unneeded strings from a list. Instead of manually removing each one of them (and even adding guards for the ones you know might not even exist in the list, hoping you don't miss any of those), just define a blacklist of terms you never want in your list and exclude them. If you choose a set as a data structure for that blacklist, you only need to iterate once over your list and checking if each element is in the blacklist is $mathcal{O}(1)$, making this algorithm $mathcal{O}(n)$.



      Your code on the other hand is $mathcal{O}(n)$ for every single term you remove, because the whole list needs to be checked for the item in the worst case, and twice that if you first check if a term exists in the list with in, which is also $mathcal{O}(n)$. This makes your code $mathcal{O}(nk)$ with $n$ the list of methods and $k$ the number of terms you want removed.



      blacklist = {"instance", "of", ...}

      for methods in c.Win32_VideoController():
      methods = [m for m in str(methods).split() if m not in blacklist]
      # do something with it





      share|improve this answer











      $endgroup$
















        8












        8








        8





        $begingroup$

        I fully agree with the answer by @BaileyParker. I have basically no idea what any of your variables are. Or what your code is actually supposed to achieve. And indeed, there is probably a better way to achieve what you want in this case. However, knowing how to do string and list parsing efficiently is also sometimes necessary, so this is how you could have done that better.



        In your code, most of the lines are spent on removing unneeded strings from a list. Instead of manually removing each one of them (and even adding guards for the ones you know might not even exist in the list, hoping you don't miss any of those), just define a blacklist of terms you never want in your list and exclude them. If you choose a set as a data structure for that blacklist, you only need to iterate once over your list and checking if each element is in the blacklist is $mathcal{O}(1)$, making this algorithm $mathcal{O}(n)$.



        Your code on the other hand is $mathcal{O}(n)$ for every single term you remove, because the whole list needs to be checked for the item in the worst case, and twice that if you first check if a term exists in the list with in, which is also $mathcal{O}(n)$. This makes your code $mathcal{O}(nk)$ with $n$ the list of methods and $k$ the number of terms you want removed.



        blacklist = {"instance", "of", ...}

        for methods in c.Win32_VideoController():
        methods = [m for m in str(methods).split() if m not in blacklist]
        # do something with it





        share|improve this answer











        $endgroup$



        I fully agree with the answer by @BaileyParker. I have basically no idea what any of your variables are. Or what your code is actually supposed to achieve. And indeed, there is probably a better way to achieve what you want in this case. However, knowing how to do string and list parsing efficiently is also sometimes necessary, so this is how you could have done that better.



        In your code, most of the lines are spent on removing unneeded strings from a list. Instead of manually removing each one of them (and even adding guards for the ones you know might not even exist in the list, hoping you don't miss any of those), just define a blacklist of terms you never want in your list and exclude them. If you choose a set as a data structure for that blacklist, you only need to iterate once over your list and checking if each element is in the blacklist is $mathcal{O}(1)$, making this algorithm $mathcal{O}(n)$.



        Your code on the other hand is $mathcal{O}(n)$ for every single term you remove, because the whole list needs to be checked for the item in the worst case, and twice that if you first check if a term exists in the list with in, which is also $mathcal{O}(n)$. This makes your code $mathcal{O}(nk)$ with $n$ the list of methods and $k$ the number of terms you want removed.



        blacklist = {"instance", "of", ...}

        for methods in c.Win32_VideoController():
        methods = [m for m in str(methods).split() if m not in blacklist]
        # do something with it






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 17 hours ago

























        answered 18 hours ago









        GraipherGraipher

        27.5k54498




        27.5k54498

























            20












            $begingroup$

            Let's ignore efficiency. It took me five minutes to figure out what you were trying to do. In the kindest way possible, this is a mess. But let's fix that!



            Your variable names are terrible. I have no idea what an ass is. What about an asss? Surely that's a bad idea, because it's very easy to mistake one for the other. Even if it wasn't, what are they? A variable name should describe what it holds. A bunch of random characters aren't helpful. Same goes for gpu_ouy. Is that a typo? What are gpu_a and gpu_b? What is aq? What is c? What is saa? None of these variables names help someone reading your code understand their function.



            Don't use len in a for loop. The idiomatic python approach is to just iterate over the collection (and let it deal with lengths and indices). So instead of:



            for x in range(len(c.Win32_VideoController())):
            ass = str(c.Win32_VideoController()[x])


            Use this:



            for controller in c.Win32_VideoController():
            # do something with controller...
            pass


            Some random points before we get to the big issue:




            • In sqa =int(((int(str(saa[1]).replace(";",""))/1024)/1024)/1000), use // instead of calling int so much. This does floor division. So int(int(x / 1024) / 1024) is the same as x // 1024 // 1024. But then you could just merge them: x // (1024 * 1024). But what are those numbers? I suspect you're converting from bytes to GB (expect 1000 MB = 1 GB isn't correct unless you're dealing with harddrives, which sometimes define the measurements like so). So instead use a constant: BYTES_PER_GB = 1024 * 1024 * 1000. Then do: int(vram_size_bytes) // BYTES_PER_GB.

            • Fix your spacing and formatting. PEP8 your code!

            • What is saa[1] above? You have some many magic indices that no one can discern without understanding the value of str(controller). Prefer giving things descriptive names (use variables, heck overuse variables to make things clear) to magic indices.


            • remove can fail (it raises a ValueError if the element isn't found in the list).

            • You don't need to initialize gpu_a and gpu_b (ex. gpu_a = "" is unnecessary), because later you assign stuff to them. They will be initialized on first assignment.


            But now the largest issue: you're doing a ton of extra work that you almost certainly don't have to do! I can't seem to find good docs for wmi's wrapping around this, but according to the microsoft docs, this probably returns an object of some type. That means instead of all of this convoluted and fragile string parsing you're attempting, you can probably get at the information you want by just doing controller.AdapterRAM // BYTES_PER_GB or controller.Description (where controller comes from for controller in wmi.WMI().Win32_VideoController()). Open up a Python REPL by running python3 and then run the following:



            >>> import wmi
            >>> controller = wmi.WMI().Win32_VideoController()[0]
            >>> help(controller)
            >>> dir(controller)


            That should give you an idea of all of the information you can get from it. You don't need to be doing all that string parsing! The information is already available on properties of the object!






            share|improve this answer









            $endgroup$













            • $begingroup$
              Strictly speaking, one GB is 1000 MB and one MB is 1000 KB, but one GiB is 1024 MiB and one MiB is 1024 KiB. Going by the standards as defined by the IEC, that is.
              $endgroup$
              – vurp0
              3 hours ago
















            20












            $begingroup$

            Let's ignore efficiency. It took me five minutes to figure out what you were trying to do. In the kindest way possible, this is a mess. But let's fix that!



            Your variable names are terrible. I have no idea what an ass is. What about an asss? Surely that's a bad idea, because it's very easy to mistake one for the other. Even if it wasn't, what are they? A variable name should describe what it holds. A bunch of random characters aren't helpful. Same goes for gpu_ouy. Is that a typo? What are gpu_a and gpu_b? What is aq? What is c? What is saa? None of these variables names help someone reading your code understand their function.



            Don't use len in a for loop. The idiomatic python approach is to just iterate over the collection (and let it deal with lengths and indices). So instead of:



            for x in range(len(c.Win32_VideoController())):
            ass = str(c.Win32_VideoController()[x])


            Use this:



            for controller in c.Win32_VideoController():
            # do something with controller...
            pass


            Some random points before we get to the big issue:




            • In sqa =int(((int(str(saa[1]).replace(";",""))/1024)/1024)/1000), use // instead of calling int so much. This does floor division. So int(int(x / 1024) / 1024) is the same as x // 1024 // 1024. But then you could just merge them: x // (1024 * 1024). But what are those numbers? I suspect you're converting from bytes to GB (expect 1000 MB = 1 GB isn't correct unless you're dealing with harddrives, which sometimes define the measurements like so). So instead use a constant: BYTES_PER_GB = 1024 * 1024 * 1000. Then do: int(vram_size_bytes) // BYTES_PER_GB.

            • Fix your spacing and formatting. PEP8 your code!

            • What is saa[1] above? You have some many magic indices that no one can discern without understanding the value of str(controller). Prefer giving things descriptive names (use variables, heck overuse variables to make things clear) to magic indices.


            • remove can fail (it raises a ValueError if the element isn't found in the list).

            • You don't need to initialize gpu_a and gpu_b (ex. gpu_a = "" is unnecessary), because later you assign stuff to them. They will be initialized on first assignment.


            But now the largest issue: you're doing a ton of extra work that you almost certainly don't have to do! I can't seem to find good docs for wmi's wrapping around this, but according to the microsoft docs, this probably returns an object of some type. That means instead of all of this convoluted and fragile string parsing you're attempting, you can probably get at the information you want by just doing controller.AdapterRAM // BYTES_PER_GB or controller.Description (where controller comes from for controller in wmi.WMI().Win32_VideoController()). Open up a Python REPL by running python3 and then run the following:



            >>> import wmi
            >>> controller = wmi.WMI().Win32_VideoController()[0]
            >>> help(controller)
            >>> dir(controller)


            That should give you an idea of all of the information you can get from it. You don't need to be doing all that string parsing! The information is already available on properties of the object!






            share|improve this answer









            $endgroup$













            • $begingroup$
              Strictly speaking, one GB is 1000 MB and one MB is 1000 KB, but one GiB is 1024 MiB and one MiB is 1024 KiB. Going by the standards as defined by the IEC, that is.
              $endgroup$
              – vurp0
              3 hours ago














            20












            20








            20





            $begingroup$

            Let's ignore efficiency. It took me five minutes to figure out what you were trying to do. In the kindest way possible, this is a mess. But let's fix that!



            Your variable names are terrible. I have no idea what an ass is. What about an asss? Surely that's a bad idea, because it's very easy to mistake one for the other. Even if it wasn't, what are they? A variable name should describe what it holds. A bunch of random characters aren't helpful. Same goes for gpu_ouy. Is that a typo? What are gpu_a and gpu_b? What is aq? What is c? What is saa? None of these variables names help someone reading your code understand their function.



            Don't use len in a for loop. The idiomatic python approach is to just iterate over the collection (and let it deal with lengths and indices). So instead of:



            for x in range(len(c.Win32_VideoController())):
            ass = str(c.Win32_VideoController()[x])


            Use this:



            for controller in c.Win32_VideoController():
            # do something with controller...
            pass


            Some random points before we get to the big issue:




            • In sqa =int(((int(str(saa[1]).replace(";",""))/1024)/1024)/1000), use // instead of calling int so much. This does floor division. So int(int(x / 1024) / 1024) is the same as x // 1024 // 1024. But then you could just merge them: x // (1024 * 1024). But what are those numbers? I suspect you're converting from bytes to GB (expect 1000 MB = 1 GB isn't correct unless you're dealing with harddrives, which sometimes define the measurements like so). So instead use a constant: BYTES_PER_GB = 1024 * 1024 * 1000. Then do: int(vram_size_bytes) // BYTES_PER_GB.

            • Fix your spacing and formatting. PEP8 your code!

            • What is saa[1] above? You have some many magic indices that no one can discern without understanding the value of str(controller). Prefer giving things descriptive names (use variables, heck overuse variables to make things clear) to magic indices.


            • remove can fail (it raises a ValueError if the element isn't found in the list).

            • You don't need to initialize gpu_a and gpu_b (ex. gpu_a = "" is unnecessary), because later you assign stuff to them. They will be initialized on first assignment.


            But now the largest issue: you're doing a ton of extra work that you almost certainly don't have to do! I can't seem to find good docs for wmi's wrapping around this, but according to the microsoft docs, this probably returns an object of some type. That means instead of all of this convoluted and fragile string parsing you're attempting, you can probably get at the information you want by just doing controller.AdapterRAM // BYTES_PER_GB or controller.Description (where controller comes from for controller in wmi.WMI().Win32_VideoController()). Open up a Python REPL by running python3 and then run the following:



            >>> import wmi
            >>> controller = wmi.WMI().Win32_VideoController()[0]
            >>> help(controller)
            >>> dir(controller)


            That should give you an idea of all of the information you can get from it. You don't need to be doing all that string parsing! The information is already available on properties of the object!






            share|improve this answer









            $endgroup$



            Let's ignore efficiency. It took me five minutes to figure out what you were trying to do. In the kindest way possible, this is a mess. But let's fix that!



            Your variable names are terrible. I have no idea what an ass is. What about an asss? Surely that's a bad idea, because it's very easy to mistake one for the other. Even if it wasn't, what are they? A variable name should describe what it holds. A bunch of random characters aren't helpful. Same goes for gpu_ouy. Is that a typo? What are gpu_a and gpu_b? What is aq? What is c? What is saa? None of these variables names help someone reading your code understand their function.



            Don't use len in a for loop. The idiomatic python approach is to just iterate over the collection (and let it deal with lengths and indices). So instead of:



            for x in range(len(c.Win32_VideoController())):
            ass = str(c.Win32_VideoController()[x])


            Use this:



            for controller in c.Win32_VideoController():
            # do something with controller...
            pass


            Some random points before we get to the big issue:




            • In sqa =int(((int(str(saa[1]).replace(";",""))/1024)/1024)/1000), use // instead of calling int so much. This does floor division. So int(int(x / 1024) / 1024) is the same as x // 1024 // 1024. But then you could just merge them: x // (1024 * 1024). But what are those numbers? I suspect you're converting from bytes to GB (expect 1000 MB = 1 GB isn't correct unless you're dealing with harddrives, which sometimes define the measurements like so). So instead use a constant: BYTES_PER_GB = 1024 * 1024 * 1000. Then do: int(vram_size_bytes) // BYTES_PER_GB.

            • Fix your spacing and formatting. PEP8 your code!

            • What is saa[1] above? You have some many magic indices that no one can discern without understanding the value of str(controller). Prefer giving things descriptive names (use variables, heck overuse variables to make things clear) to magic indices.


            • remove can fail (it raises a ValueError if the element isn't found in the list).

            • You don't need to initialize gpu_a and gpu_b (ex. gpu_a = "" is unnecessary), because later you assign stuff to them. They will be initialized on first assignment.


            But now the largest issue: you're doing a ton of extra work that you almost certainly don't have to do! I can't seem to find good docs for wmi's wrapping around this, but according to the microsoft docs, this probably returns an object of some type. That means instead of all of this convoluted and fragile string parsing you're attempting, you can probably get at the information you want by just doing controller.AdapterRAM // BYTES_PER_GB or controller.Description (where controller comes from for controller in wmi.WMI().Win32_VideoController()). Open up a Python REPL by running python3 and then run the following:



            >>> import wmi
            >>> controller = wmi.WMI().Win32_VideoController()[0]
            >>> help(controller)
            >>> dir(controller)


            That should give you an idea of all of the information you can get from it. You don't need to be doing all that string parsing! The information is already available on properties of the object!







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 20 hours ago









            Bailey ParkerBailey Parker

            2,4041015




            2,4041015












            • $begingroup$
              Strictly speaking, one GB is 1000 MB and one MB is 1000 KB, but one GiB is 1024 MiB and one MiB is 1024 KiB. Going by the standards as defined by the IEC, that is.
              $endgroup$
              – vurp0
              3 hours ago


















            • $begingroup$
              Strictly speaking, one GB is 1000 MB and one MB is 1000 KB, but one GiB is 1024 MiB and one MiB is 1024 KiB. Going by the standards as defined by the IEC, that is.
              $endgroup$
              – vurp0
              3 hours ago
















            $begingroup$
            Strictly speaking, one GB is 1000 MB and one MB is 1000 KB, but one GiB is 1024 MiB and one MiB is 1024 KiB. Going by the standards as defined by the IEC, that is.
            $endgroup$
            – vurp0
            3 hours ago




            $begingroup$
            Strictly speaking, one GB is 1000 MB and one MB is 1000 KB, but one GiB is 1024 MiB and one MiB is 1024 KiB. Going by the standards as defined by the IEC, that is.
            $endgroup$
            – vurp0
            3 hours ago











            2












            $begingroup$

            To add on to what @BaileyParker said, instead of phrasing the WMI string directly, you should use the wmi_property command to get the value of the property you are interested in. You can get a list of properties from the Microsoft documentation: Win32_VideoController



            For example, you could do something like this:



            import json
            import wmi

            controllers = wmi.WMI().Win32_VideoController()

            gpu_data = list()

            for controller in controllers:
            controller_info = {
            'Name': controller.wmi_property('Name').value,
            'HRes': controller.wmi_property('CurrentHorizontalResolution').value,
            'VRes': controller.wmi_property('CurrentVerticalResolution').value,
            }
            gpu_data.append(controller_info)

            print json.dumps(gpu_data, indent=4)


            On my machine it prints the output:



            [
            {
            "VRes": 1080,
            "Name": "NVIDIA GeForce GTX 1050",
            "HRes": 1920
            }
            ]





            share|improve this answer











            $endgroup$













            • $begingroup$
              I would make that for loop a list comprehension. Otherwise this seems to be the solution the OP actually needs in this case.
              $endgroup$
              – Graipher
              9 hours ago
















            2












            $begingroup$

            To add on to what @BaileyParker said, instead of phrasing the WMI string directly, you should use the wmi_property command to get the value of the property you are interested in. You can get a list of properties from the Microsoft documentation: Win32_VideoController



            For example, you could do something like this:



            import json
            import wmi

            controllers = wmi.WMI().Win32_VideoController()

            gpu_data = list()

            for controller in controllers:
            controller_info = {
            'Name': controller.wmi_property('Name').value,
            'HRes': controller.wmi_property('CurrentHorizontalResolution').value,
            'VRes': controller.wmi_property('CurrentVerticalResolution').value,
            }
            gpu_data.append(controller_info)

            print json.dumps(gpu_data, indent=4)


            On my machine it prints the output:



            [
            {
            "VRes": 1080,
            "Name": "NVIDIA GeForce GTX 1050",
            "HRes": 1920
            }
            ]





            share|improve this answer











            $endgroup$













            • $begingroup$
              I would make that for loop a list comprehension. Otherwise this seems to be the solution the OP actually needs in this case.
              $endgroup$
              – Graipher
              9 hours ago














            2












            2








            2





            $begingroup$

            To add on to what @BaileyParker said, instead of phrasing the WMI string directly, you should use the wmi_property command to get the value of the property you are interested in. You can get a list of properties from the Microsoft documentation: Win32_VideoController



            For example, you could do something like this:



            import json
            import wmi

            controllers = wmi.WMI().Win32_VideoController()

            gpu_data = list()

            for controller in controllers:
            controller_info = {
            'Name': controller.wmi_property('Name').value,
            'HRes': controller.wmi_property('CurrentHorizontalResolution').value,
            'VRes': controller.wmi_property('CurrentVerticalResolution').value,
            }
            gpu_data.append(controller_info)

            print json.dumps(gpu_data, indent=4)


            On my machine it prints the output:



            [
            {
            "VRes": 1080,
            "Name": "NVIDIA GeForce GTX 1050",
            "HRes": 1920
            }
            ]





            share|improve this answer











            $endgroup$



            To add on to what @BaileyParker said, instead of phrasing the WMI string directly, you should use the wmi_property command to get the value of the property you are interested in. You can get a list of properties from the Microsoft documentation: Win32_VideoController



            For example, you could do something like this:



            import json
            import wmi

            controllers = wmi.WMI().Win32_VideoController()

            gpu_data = list()

            for controller in controllers:
            controller_info = {
            'Name': controller.wmi_property('Name').value,
            'HRes': controller.wmi_property('CurrentHorizontalResolution').value,
            'VRes': controller.wmi_property('CurrentVerticalResolution').value,
            }
            gpu_data.append(controller_info)

            print json.dumps(gpu_data, indent=4)


            On my machine it prints the output:



            [
            {
            "VRes": 1080,
            "Name": "NVIDIA GeForce GTX 1050",
            "HRes": 1920
            }
            ]






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 9 hours ago

























            answered 10 hours ago









            Mark OmoMark Omo

            209418




            209418












            • $begingroup$
              I would make that for loop a list comprehension. Otherwise this seems to be the solution the OP actually needs in this case.
              $endgroup$
              – Graipher
              9 hours ago


















            • $begingroup$
              I would make that for loop a list comprehension. Otherwise this seems to be the solution the OP actually needs in this case.
              $endgroup$
              – Graipher
              9 hours ago
















            $begingroup$
            I would make that for loop a list comprehension. Otherwise this seems to be the solution the OP actually needs in this case.
            $endgroup$
            – Graipher
            9 hours ago




            $begingroup$
            I would make that for loop a list comprehension. Otherwise this seems to be the solution the OP actually needs in this case.
            $endgroup$
            – Graipher
            9 hours ago










            tadas is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            tadas is a new contributor. Be nice, and check out our Code of Conduct.













            tadas is a new contributor. Be nice, and check out our Code of Conduct.












            tadas is a new contributor. Be nice, and check out our Code of Conduct.
















            Thanks for contributing an answer to Code Review Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217532%2fextract-all-gpu-name-model-and-gpu-ram%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Couldn't open a raw socket. Error: Permission denied (13) (nmap)Is it possible to run networking commands...

            VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...

            Why not use the yoke to control yaw, as well as pitch and roll? Announcing the arrival of...