[python-win32] COM works from IDLE but not when file executed from Windows Explorer
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Thu Mar 15 00:43:17 CET 2007
En Wed, 14 Mar 2007 13:41:17 -0300, Tim Roberts <timr at probo.com> escribió:
>> if __name__ == "__main__":
>> mp = Dispatch("WMPlayer.OCX")
>> tune = mp.newMedia('my_file.mp3')
>> mp.currentPlaylist.appendItem(tune)
>> mp.controls.play()
>> raw_input("Press Enter to stop playing")
>> mp.controls.stop()
>
> My guess is that you aren't in the same directory, so that "my_file.mp3"
> is not found. Explorer might be setting the starting directory to the
> directory that contains python.exe (since that's what it is really
> executing) instead of the directory with your script.
>
> You might try providing the full path to the file, instead of just a
> relative path.
In addition, you may obtain the directory where your script resides using:
import os
print os.path.dirname(os.path.abspath(__file__))
(I suggest computing that early on your program, because if the current
directory changes, abspath will give a wrong result)
--
Gabriel Genellina
More information about the Python-win32
mailing list