3

I'm currently wondering how to list the constants in win32com in python,

for example using excel win32com.client.Dispatch('Excel.Application')

Is there a way to display all constants using win32com.client.Constants ?

Or does someone know where i could find win32com's documentation ? Because all the links I found are dead ...

1

3 Answers 3

1

To find out what Com applications you can use... See http://timgolden.me.uk/pywin32-docs/html/com/win32com/HTML/QuickStartClientCom.html

Basically you can't know for sure. Sorry. Each computer will have a different list based on the software installed, the webpage I linked suggests using pyWins ComBrowser, however I haven't ever found it that useful.

My normal approach is 'I want to interface with application X in Python... lets google "python com X" and see what comes up' or 'I want to interface with application X in Python.. lets look through the documentation of AppX for references to COM'

Afterall you'll want to have some form of documentation to that programmes COM interface in order to be able to do anything meaningful with the program (other than opening it).

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah i did my best to find, because the application using com which i wanted to interface was internal application to my company, so Google wasn't my friend in that case .. Finally, i found some intern documents and asked persons in charge of this tool development. So it's OK ! But i still really don't know where to find a win32com library documentation, it seems not existing ..
This might help with win32com docs.. docs.activestate.com/activepython/2.5/pywin32/html/com/win32com/… or just try import win32com and help(win32com) etc I found that in windows I have installed in my python folder "Python for Windows Documentation" (access via start menu or C:\PythonXX\Lib\site-packages\PyWin32.chm) search in that for win32com and it gives you some stuff. There are also books available on Python Com programming.
1

The answer given by @CastleH in his comment pointed me in the right direction: help() helped me a lot, but you have to use it on module-level!

For example,

import win32print
help(win32print)

gives you all constants in win32print. You can do the same for every module in win32com (for a full list of modules see the win32com documentation, section modules).

Using help(win32com)did not help me a lot since it is mainly listing the packages

Comments

1

To list available constants, you can do something like:

import win32com

for k, v in win32com.client.constants.__dicts__[0].items(): 
    print("{:<45}: {}".format(k, v))

#  __module__                                   : win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x9
#  xl3DBar                                      : -4099
#  xl3DEffects1                                 : 13
#  xl3DEffects2                                 : 14
#  xl3DSurface                                  : -4103
#  ...

The best resource for pywin32, even in 2020 (16+ years after its creation), is the source code1.

It turns out that win32com.client.constants is an instance of the Constants class:

class Constants:
  """A container for generated COM constants.
  """
  def __init__(self):
    self.__dicts__ = [] # A list of dictionaries
  def __getattr__(self, a):
    for d in self.__dicts__:
      if a in d:
        return d[a]
    raise AttributeError(a)

# And create an instance.
constants = Constants()

The constants are all stored in self.__dicts__ which is a list of dictionaries. That list happens to contain only a single dictionary.

Knowing this, you can iterate through the dictionary (as done above) to see what constants are available.


1 For dead links, try The Internet Archive's Wayback Machine. There are plugins for various browsers which make searching for archived versions of a page easy or automatic.

1 Comment

In 2025 (just few years later) it seems that the dict was emptied :-D Either "they" have found your post and "closed the leak", or "win32" became to be too old and indeed new interface is needed ;-) # Currently didn't find a way to enumerate all constants from there (actually I need just get the "text" of certain constant value, but even this doesn't work now - even if I know - where MS describes the available constant values for related parameter).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.