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.
sys
modulesys
module contains system-specific functionality. We have already seen that the sys.argv
list contains the command-line arguments.sys
module gives us that information.sys
module has a version_info
tuple that gives us the version information. The first entry is the major version. We can pull out this information to use it.logging
modulelogging
module.stdlib_logging.py
:cat
command is used in the command line to read the 'test.log' file. If the cat
command is not available, you can open the test.log
file in a text editor instead.os
module for interacting with the operating system, the platform
module for information about the platform i.e. the operating system and the logging
module 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 the
osmodule is different from the string method
join()` that we've used elsewhere in this book.logging
module to write all the messages in a particular format to the file we have specified.