How can i change an Object type ?

Jerry Hill malaclypse2 at gmail.com
Tue Jul 3 23:35:30 EDT 2007


On 7/3/07, KuhlmannSascha <Sascha.Kuhlmann at gmail.com> wrote:
> I am focussing on the Playlists of the object UserPlaylist.
> (CodeLine:   if curPlaylist.Kind == 2:)
> After that i should be sure to have a UserPlaylist, but Python stops
> with an exception that the requested Attribute "Smart"  is not
> available

It looks like win32com thinks you have a IITPlaylist, and you really
have a subclass of that, a IITUserPlaylist.  You need to cast it like
this:

import win32com.client
iTunes = win32com.client.gencache.EnsureDispatch('iTunes.Application')
playlists = iTunes.LibrarySource.Playlists
for playlist in playlists:
    if playlist.Kind == 2:
        playlist = win32com.client.CastTo(playlist, 'IITUserPlaylist')
        print "Name:  ", playlist.Name
        print "Kind:  ", playlist.Kind
        print "Smart: ", playlist.Smart
        print

-- 
Jerry



More information about the Python-list mailing list