我试图编写一个脚本,使用默认的Windows应用程序播放电影,但当我尝试运行时,出现错误:强制转换为Unicode:需要字符串或缓冲区,找到函数。
我该如何继续进行?
import os
print 'Push "enter" to play movie'
raw_input()
def filename():
filename = movie.mp4
os.system("start " + filename)
open(filename)
我试图编写一个脚本,使用默认的Windows应用程序播放电影,但当我尝试运行时,出现错误:强制转换为Unicode:需要字符串或缓冲区,找到函数。
我该如何继续进行?
import os
print 'Push "enter" to play movie'
raw_input()
def filename():
filename = movie.mp4
os.system("start " + filename)
open(filename)
movie
的变量,当您执行 filename = movie.mp4
时,它会将 movie
的函数 mp4
分配给变量 filename
。无论如何,我认为没有必要这样做。def play_movie(path):
from os import startfile
startfile(path)
这就是你“播放”功能所需的全部内容。如果我是你,我会将它封装在一个类中,例如:
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()