Skip to content
Advertisement

Defining variable as long as array

I’m trying to write basic program that displays system properties such as total physical memory, processor information and operating system. But, I’m having trouble with learning ram total physical memory.

I found total physical memory but it gave me value as a string in bytes.

I wanted to convert it to mb so I have to convert it to an int.

I tried to split them as elements of an array. I separated them but, there is a problem. How can I assign these values (elements of array) as int to a variable?

With a for loop?

My code is below:

import wmi

pc = wmi.WMI ()
for i in pc.Win32_ComputerSystem ():
  print(i.TotalPhysicalMemory)
  arr=list(i.TotalPhysicalMemory)
  length_of_array=len(arr)
for i in range(0, length_of_array):
    myvar=str(arr[i])
    print(myvar)

This code turns the physical memory string into an array and prints elements.

I want to turn i.TotalPhysicalMemory into an integer value and divide by 1000000. How can I do it?

Advertisement

Answer

I want to turn TotalPhysicalMemory into an integer value and divide by 1000000. How can i do it?

to turn TotalPhysicalMemory into an integer, use int(i.TotalPhysicalMemory). This doasn’t overwrite the variable, so you’ll have to save it in another one.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement