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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0