Python 3: Reading System Information (date, sys, platform, os)

Python logo

This is the first post of a series of articles about Python 3. Python 3 support has been added in GeeXLab and has been improved in GeeXLab, especially in the latest release 0.27.2.

On the Linux version, the Python 3 plugin is linked against Python 3.6 shared object (Python 3.6 is standard version on Linux Mint 19.1). On Windows, Python is not available in a standard installation. GeeXLab is shipped with Python 3.7.2, so you don’t need to install Python. But if you already have Python 3.7 installed on your system with lot of particular modules, you can tell GeeXLab to use this new Python home. Just edit the start_set_python_home.bat in GeeXLab folder and change the /python3_home.

For this first article, let’s start with simple but nonetheless important topic: the reading of system information. Python comes with several modules for retrieving system information: sys, platform and os. We’ll see how to display the current date/time as well.

To test this Python 3 demo, you need GeeXLab 0.27.2+. Download the demo, unzip the archive where you want and drag and drop the python3-demopack/py3-01-system-info/main.xml into GeeXLab.

Here is what I get on Linux Mint 19.1 (Python 3.6.7):

Python 3 - reading system info on Linux - GeeXLab demo

And on Windows 10 (Python 3.7.2):

Python 3 - reading system info on Windows - GeeXLab demo

All interesting things can be found in the file. By default live-coding is enabled in this demo, so you can edit the while GeeXLab is running and you will see your changes instantly.

For this demo, the required imports are the following:

import sys
import platform
import sysconfig
import os
import time
from time import gmtime, strftime
import datetime


Date and time: time and datetime modules

The elapsed time is displayed with:

ts = time.time()
gh_imgui.text("%.1f sec" % ts)

The date and time is displayed with:

st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')

and with :

current_date = strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())


sys module

The information displayed by the sys module:

gh_imgui.text_rgba("sys.executable", color1[0], color1[1], color1[2], color1[3])
if (sys.executable == ""):
gh_imgui.text_rgba("sys.float_info", color1[0], color1[1], color1[2], color1[3])
gh_imgui.text_rgba("sys.hexversion", color1[0], color1[1], color1[2], color1[3])
gh_imgui.text_rgba("sys.version", color1[0], color1[1], color1[2], color1[3])
gh_imgui.text_rgba("sys.api_version", color1[0], color1[1], color1[2], color1[3])
gh_imgui.text_rgba("sys.version_info", color1[0], color1[1], color1[2], color1[3])
gh_imgui.text_rgba("sys.platform", color1[0], color1[1], color1[2], color1[3])

color1 is a tuple:

color1 = (0.2, 0.6, 1.0, 1.0)


platform module

The information displayed by the platform module:

gh_imgui.text_rgba("platform.architecture()", color1[0], color1[1], color1[2], color1[3])
gh_imgui.text_rgba("platform.processor()", color1[0], color1[1], color1[2], color1[3])
gh_imgui.text_rgba("platform.system()", color1[0], color1[1], color1[2], color1[3])
gh_imgui.text_rgba("platform.uname()", color1[0], color1[1], color1[2], color1[3])


sysconfig module

The information displayed by the sysconfig module:

gh_imgui.text_rgba("sysconfig.get_python_version()", color1[0], color1[1], color1[2], color1[3])
gh_imgui.text_rgba("sysconfig.get_path_names()", color1[0], color1[1], color1[2], color1[3])
gh_imgui.text_rgba("sysconfig.get_path('stdlib')", color1[0], color1[1], color1[2], color1[3])


os module

The os seems to have a bug on Linux Mint 19.1 with the os.getlogin() function. The Python interpreter outputs the following error:

Error line: 153 - Error object:  - Error data: OSError(25, 'Inappropriate ioctl for device')

The same function works perfectly on Windows. So I used the sys.platform info to test the platform:

if (sys.platform == "win32"):
  gh_imgui.text_rgba("os.getlogin()", color1[0], color1[1], color1[2], color1[3])
gh_imgui.text_rgba("os.getpid()", color1[0], color1[1], color1[2], color1[3])
gh_imgui.text_rgba("os.cpu_count()", color1[0], color1[1], color1[2], color1[3])

Leave a Comment

Your email address will not be published. Required fields are marked *