Python code not working to delete an existing playlist
Hi there. I have been using VbScripts with itunes since circa 2010, and they always worked to perfection.
However, since Vbscript is outdated and Python is the new coqueluch in town (everybody is catching it), I decided to convert my programs into it.
However, I'm totally puzzled why the code is not working to delete a playlist, as it did so well in Vbscript. The "compiler" always run the line that deletes the playlist, but it doesn't get deleted.
However, the part where a track is being added to the new playlist is working well.
Anybody with good Python skills could please help me to debug this?
Thank you so much
# iTunes API
import win32com.client
iTunesApp = win32com.client.Dispatch("iTunes.Application")
def Cria_PL(PL_nome):
PL = iTunesApp.LibrarySource.Playlists.ItemByName(PL_nome)
if PL is not None:
r= PL.delete
# CRIA PLAYLIST
iTunesApp.CreatePlaylist(PL_nome)
PL = iTunesApp.LibrarySource.Playlists.ItemByName(PL_nome)
return PL
# CREATES PLAYLIST
New_PL = None
#Move_files
New_PL = Cria_PL("Test")
arq="D:/MP3/Favorites/Abba - Fernando.mp3"
print(arq)
New_PL.AddFile(arq)
New_PL = None