-1

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?

Axe319
  • 4,255
  • 3
  • 15
  • 31
  • @PranavHosangadi It's not really relevant. `i.TotalPhysicalMemory` is a string. The question is just a roundabout way of asking how to divide a string by an integer. – Axe319 Apr 29 '22 at 20:02
  • 1
    @Axe319 ah, I see. I'm not familiar with wmi, and since OP said _" I found total physical memory but it gave me value in byte"_ I thought they meant it returns a `bytes` object. Well, "string to int" that has lots of duplicates too, but somebody else will have to vote – Pranav Hosangadi Apr 29 '22 at 20:03
  • 1
    Does this answer your question? [How to convert strings into integers?](https://stackoverflow.com/questions/642154/how-to-convert-strings-into-integers) – Axe319 Apr 29 '22 at 20:05

1 Answers1

0

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.

vale
  • 91
  • 6