views:

136

answers:

1

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.

+1  A: 

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;-).

Alex Martelli
Thanks. That was exactly what I was looking for!
nunos