COM

To load a Component Object Model (COM library) you pass in the library’s Program ID. To view the COM libraries that are available on your computer you can run the get_com_info() function.

Attention

This example is only valid on Windows.

Here we load the FileSystemObject and include the 'com' argument to indicate that it is a COM library

>>> from msl.loadlib import LoadLibrary
>>> com = LoadLibrary('Scripting.FileSystemObject', 'com')
>>> com
<LoadLibrary libtype=POINTER(IFileSystem3) path=Scripting.FileSystemObject>

We can then use the library to create, edit and close a text file by using the CreateTextFile method

>>> fp = com.lib.CreateTextFile('a_new_file.txt')
>>> fp.Write('This is a test.')
0
>>> fp.Close()
0

Verify that the file exists and that the text is correct

>>> com.lib.FileExists('a_new_file.txt')
True
>>> file = com.lib.OpenTextFile('a_new_file.txt')
>>> file.ReadAll()
'This is a test.'
>>> file.Close()
0