CAUTION: If you find the topics in this chapter too advanced, you may skip this chapter. However, I highly recommend coming back to this chapter when you are more comfortable with programming using Python.
sysmodule contains system-specific functionality. We have already seen that the
sys.argvlist contains the command-line arguments.
sysmodule gives us that information.
sysmodule has a
version_infotuple that gives us the version information. The first entry is the major version. We can pull out this information to use it.
catcommand is used in the command line to read the 'test.log' file. If the
catcommand is not available, you can open the
test.logfile in a text editor instead.
osmodule for interacting with the operating system, the
platformmodule for information about the platform i.e. the operating system and the
loggingmodule to log information.
platform.platform()(for more information, see
import platform; help(platform)). If it is Windows, we figure out the home drive, the home folder and the filename where we want to store the information. Putting these three parts together, we get the full location of the file. For other platforms, we need to know just the home folder of the user and we get the full location of the file.
os.path.join()function to put these three parts of the location together. The reason to use a special function rather than just adding the strings together is because this function will ensure the full location matches the format expected by the operating system. Note: the
join()' method we use here that's part of theos
module is different from the string methodjoin()` that we've used elsewhere in this book.
loggingmodule to write all the messages in a particular format to the file we have specified.