示例代码:
import os
from ffvideo import VideoStream
filespath = []
vidDuration = []
vidCode = []
class getVidInfo(QtCore.QThread):
def __init__(self):
AtCore.QThread.__init__(self)
def run(self):
for x in xrange(14)
filename = filespath[x]
filename = os.path.basename(filename)
vs = VideoStream(filename)
vidDuration.append(vs.duration)
vidCodec.append(vs.codec_name)
class VideoForm(AtGui.MainWindow)
def getVideoFile(self):
for dirName, subDirList, fileList in os.walk(rootDir)
for fname in fileList:
ext = fname[-3:]
if ext in ['flv','mp4','avi','mkv']
filespath.append(os.path.join(dirName, fname))
答案 0 :(得分:0)
filespath是一个"全球"变量,在这种情况下类方法范围之外。如果要在类方法中修改它,则需要在方法中明确声明变量为全局:
class VideoForm(AtGui.MainWindow)
def getVideoFile(self):
global filespath # declare explicitly the intention of using the global one.
for dirName, subDirList, fileList in os.walk(rootDir)
for fname in fileList:
ext = fname[-3:]
if ext in ['flv','mp4','avi','mkv']
filespath.append(os.path.join(dirName, fname))
虽然不建议这样做,除非你知道自己在做什么。例如,最好将列表作为参数传递给类构造函数。