Python win32com Constants

sean's picture

I have been scripting with Python recently for most of the programming I have been doing recently and came across win32com. win32com is a powerful library available by default in ActiveState Python for Windows.  win32com allows you to access many of the Windows com objects from within Python.  The downside is that the documentation for win32com is pretty sparse.  I recently wrote a program to read other people's calendars on an Exchange server so I could summarize their utilization.  I will write about my experiences there later, but for now, one of the areas that I found very hard to find documented was how to reference constants in win32com from within Python.

If you are looking to reference a win32com constant, something like olFolderCalendar, in Python, you would reference win32com.client.constants.olFolderCalendar.  Before you are able to do that, you need to compile some extra modules within ActiveState Python to make the constants available.  To do that, go to c:\Python26\Lib\site-packages\win32com\client and run makepy.py.  This will bring up a window with a list of libraries you can compile in.  For me, I needed Outlook and Excel libraries, so I selected "Microsoft Excel 14.0 Object Library" and Microsoft Outlook 14.0 Object Library."  Once complete, I could reference the constants for both libraries.

I have run into a problem where one day everything was working and the next it stopped.  I have not figured out why that happened.  Once I do, I will update this blog.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> , <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <embed> <object> <strike> <caption>
  • Lines and paragraphs break automatically.

More information about formatting options