473,324 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

How can i change an Object type ?

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: '<win32com.gen_py.iTunes 1.9 Type Library.IITPlaylist
instance at 0x30216960>' object has no attribute 'Smart'
Any help is appreciated......

Regards
Sascha

Jul 4 '07 #1
4 1964
On 7/3/07, KuhlmannSascha <Sa*************@gmail.comwrote:
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.Ap plication')
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
Jul 4 '07 #2
KuhlmannSascha <Sa*************@gmail.comwrote:
>
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: '<win32com.gen_py.iTunes 1.9 Type Library.IITPlaylist
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, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 4 '07 #3
On Jul 4, 12:40 am, Tim Roberts <t...@probo.comwrote:
KuhlmannSascha <Sascha.Kuhlm...@gmail.comwrote:
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: '<win32com.gen_py.iTunes 1.9 Type Library.IITPlaylist
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, t...@probo.com
Providenza & Boekelheide, Inc.
These look like they could give you some pointers too:

http://www.brunningonline.net/simon/...es/001627.html
http://lazycat.org/backburner.html
http://mail.python.org/pipermail/pyt...ry/005506.html

Mike

Jul 4 '07 #4
On Jul 4, 12:14 pm, kyoso...@gmail.com wrote:
On Jul 4, 12:40 am, Tim Roberts <t...@probo.comwrote:
KuhlmannSascha <Sascha.Kuhlm...@gmail.comwrote:
>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: '<win32com.gen_py.iTunes 1.9 Type Library.IITPlaylist
>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, t...@probo.com
Providenza & Boekelheide, Inc.

These look like they could give you some pointers too:

http://www.brunningonline.net/simon/...ry/005506.html

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

Jul 5 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: oleg | last post by:
Hello! I developed COM Type Library in C#! This Com used by VB6.0, but when from vb called some property of com object ,happen error "Object required"!!! Part of C# COM: public object xxx {...
6
by: yohaas | last post by:
I'm trying to do something, not sure if it's possible or even if it makes sense, but I figured I'd throw it out there. I have a class OrderSummary that contains information about an order. I...
3
by: spielmann | last post by:
Hello I want to change the scrollbar size of windows, How can I do that with vb.net I have find this in VB6 but how can we convert simply this code. thx
3
by: Andy | last post by:
If I use Visual Studio.Net 2003 to generate "web references" for clients using either sproxy.exe (for C++) client or wsdl.exe (for C#) clients, the web service endpoint gets "baked" into the...
5
by: joeblast | last post by:
I have a Web service that gets the financial periods and hold a reference to a disconnected dataset built at initialization. Web methods work on the dataset inside the web service. Everything is...
15
by: Encapsulin | last post by:
Hello everybody. I'm trying to change src of quicktime embedded object with javascript: <html><body> <script language="JavaScript"> function Exchange() { document.qtvr.src = "sample2.pano";...
2
by: Greg Strong | last post by:
Hello All, Is it possible to change table field lookup properties in code? I've been able to change other field properties in code, however so far no luck with field lookup properties. What...
7
by: Tim Rogers | last post by:
Hi folks, this is a resolution-detect script that I used on a site. As you can see it is designed to detect when the screen resolution falls below a certain level then load an alternative style...
7
by: asdf | last post by:
May I change the value of data members of an object by using the constructor? struct A { int x; default y; } int main()
5
by: Joseph Barillari | last post by:
Hi python-list, I've just started using new-style classes and am a bit confused as to why I can't seem to alter methods with special names (__call__, etc.) of new-style class instances. In other...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.