Get system information using python
Python provides a built-in module called “platform” that enables us to fetch some of the information about our system such as OS, processor, system version, etc
Let us look at some of the methods one by one with an example for each
1. Machine type
The machine() method returns the machine type of the user. An empty string is returned if the value cannot be determined.
2. Computer’s name
The node() method returns the computer’s network name. An empty string is returned if the value cannot be determined.
3. System OS
The platform() method returns a single string identifying the underlying platform with as much useful information as possible.
This can give various information such as the OS, OS version, processor etc all in a single string.
4. Processor name
This processor() method returns the name of the processor used by the system e.g. 'amdk6', 'i386'
.
Many platforms do not provide this information and an empty string is returned if the value cannot be determined.
My system uses an Intel i3 processor and hence i386.
5. Python version
The python_version() method returns the Python version as a string 'major.minor.patchlevel'
.
Note that, unlike the Python sys.version
, the returned value will always include the patch level (it defaults to 0).
6. System’s release
The release() method returns the system’s release version. An empty string is returned if the value cannot be determined.
7. Return all the information
The uname() method returns all the output of the above methods as a nameduple.
The six attributes returned by this method are
- system
- node
- release
- version
- machine
- processor
Conclusion
Hope this article was helpful. Follow me for more cool articles on python.
Happy coding!