Reputation: 65
I was trying to make a script that would play a movie using the default windows application but when I try to run this I get the error: coercing to Unicode: need string or buffer, function found
How should I proceed with this?
import os
print 'Push "enter" to play movie'
raw_input()
def filename():
filename = movie.mp4
os.system("start " + filename)
open(filename)
Upvotes: 6
Views: 38257
Reputation: 54183
The problem you're having is that you likely have a variable named movie
, and when you do filename = movie.mp4
it's setting assigning the movie
's function mp4
to the variable filename
. In any case, I don't think there's a reason to do this.
def play_movie(path):
from os import startfile
startfile(path)
That's literally all you need for your "Play" function. If I were you, I'd wrap it in a class, something like:
class Video(object):
def __init__(self,path):
self.path = path
def play(self):
from os import startfile
startfile(self.path)
class Movie_MP4(Video):
type = "MP4"
movie = Movie_MP4(r"C:\My Documents\My Videos\Heres_a_file.mp4")
if raw_input("Press enter to play, anything else to exit") == '':
movie.play()
Upvotes: 9