Question

First of all, please excuse me for any incoherence in the tile of this question. It probably has some, but really don't know better.

This question was raised in the context of controlling iTunes via COM from python.

>>> itunes = win32com.client.Dispatch("iTunes.Application")
>>> itunes
<win32com.gen_py.iTunes 1.12 Type Library.IiTunes instance at 0x27248400>
>>> lib = itunes.LibraryPlaylist
>>> lib
<win32com.gen_py.iTunes 1.12 Type Library.IITLibraryPlaylist instance at 0x27249880>

What I would like to do is to retrieve 'IiTunes' from itunes and 'IITLibraryPlaylist' from lib. I have tried type(itunes) and type(lib) but they both only return "" and that's not what I am looking for.

Thanks.

Was it helpful?

Solution

Unfortunately I have no Windows machine at hand to try, but I think itunes.__class__ is the (old_style) class of the itunes object in question, and lib.__class__ that of lib. So looking at the __name__ attribute of the classes should give you what you desire.

It's unfortunately that these are old-style classes (so type(...) does not work right), but win32com has been around for a LONG time, from well before the shiny new-style classes were born in Python 2.2, so it's fully understandable, I think;-).

OTHER TIPS

The main reason for this attribute error is because your COM-server has shifted from late-binding (dynamic) to early binding (static).

  • In Late Binding, whenever a method is called, the object is queried for the method and if it succeeds, then the call can be made.
  • In Early Binding, the information of the object model is determined in advance from type information supplied by the object call. Early binding makes use of MakePy. Also, early binding is case sensitive.

Try:

itunes = win32com.client.dynamic.Dispatch("iTunes.Application")

This will force the COM server to set focus on the dynamic module which should give you only the COM Object of iTunes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top