How can I return system information in Python?

Regarding cross-platform: your best bet is probably to write platform-specific code, and then import it conditionally. e.g.

import sys
if sys.platform == 'win32':
  import win32_sysinfo as sysinfo
elif sys.platform == 'darwin':
  import mac_sysinfo as sysinfo
elif 'linux' in sys.platform:
  import linux_sysinfo as sysinfo
#etc

print 'Memory available:', sysinfo.memory_available()

For specific resources, as Anthony points out you can access /proc under linux. For Windows, you could have a poke around at the Microsoft Script Repository. I’m not sure where to get that kind of information on Macs, but I can think of a great website where you could ask 🙂

Leave a Comment