How can i change an Object type ?

2007-07-03 Thread KuhlmannSascha
Hi,

i tried now for several hours to read through a win32com API to access
Itunes and read out myplaylists.

First of all the Code:

import os, sys, pythoncom, win32com.client, pywintypes, sets

def showplaylists():
iTunes = win32com.client.Dispatch("iTunes.Application")
playlists = iTunes.LibrarySource.Playlists
numPlaylists = playlists.Count
while (numPlaylists != 0):
curPlaylist = playlists.Item(numPlaylists)
if curPlaylist.Kind == 2:
if curPlaylist.Smart():
numPlaylists -= 1
else:
print curPlaylist.Name
numtrack = curPlaylist.Tracks.Count
while (numtrack !=0):
curPlaylist.Tracks(numtrack).Name
numtrack -= 1
numPlaylists -= 1
showplaylists()

The current Logic is to access first Itunes and then a Playlist
Collection.
This Playlist collection returns different kind of objects for
Playlists.
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
Error MEssage:
AttributeError: '' object has no attribute 'Smart'


Any help is appreciated..

Regards
Sascha

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can i change an Object type ?

2007-07-05 Thread KuhlmannSascha
On Jul 4, 12:14 pm, [EMAIL PROTECTED] wrote:
> On Jul 4, 12:40 am, Tim Roberts <[EMAIL PROTECTED]> wrote:
>
>
>
> > KuhlmannSascha <[EMAIL PROTECTED]> wrote:
>
> > >i tried now for several hours to read through a win32com API to access
> > >Itunes and read out myplaylists.
>
> > >First of all the Code:
> > >...
> > >The current Logic is to access first Itunes and then a Playlist
> > >Collection.
> > >This Playlist collection returns different kind of objects for
> > >Playlists.
> > >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
> > >Error MEssage:
> > >AttributeError: ' > >instance at 0x30216960>' object has no attribute 'Smart'
>
> > Smart is part of IITUserPlaylist, not IITPlaylist.  You need to call
> > curPlaylist.QueryInterface to get the IITUserPlaylist, but that means
> > you'll need to know the GUID for IITUserPlaylist.  Perhaps Google will
> > help.
> > --
> > Tim Roberts, [EMAIL PROTECTED]
> > Providenza & Boekelheide, Inc.
>
> These look like they could give you some pointers too:
>
> http://www.brunningonline.net/simon/blog/archives/001627.htmlhttp://lazycat.org/backburner.htmlhttp://mail.python.org/pipermail/python-win32/2007-February/005506.html
>
> Mike

Thanks all of you !
The Casting was the issue !!!
Regards
Sascha

-- 
http://mail.python.org/mailman/listinfo/python-list