|
本帖最后由 xiop 于 2018-4-30 08:44 编辑
这是一个读取指定目录中的视频文件的函数定义,我用的python3.6总提示下面的函数第一行最后的冒号有问题。
我第一次试了下,在:
print("The file" + filePath + " doesn't exist.\nIt means there was an error calling the comparator.")
上面语句的最后加了一个分号,可编译还是提示相同的错误,这个是什么问题呢?原代码的编写者可能用的是python2的语法。
函数定义如下:- def readCMFile(filePath):
- """Read the file, so we can compute stats for video, category and overall."""
- if not os.path.exists(filePath):
- print("The file " + filePath + " doesn't exist.\nIt means there was an error calling the comparator.")
- raise Exception('error');
-
- with open(filePath) as f:
- for line in f.readlines():
- if line.startswith('cm:'):
- numbers = line.split()[1:]
- return [int(nb) for nb in numbers[:5]]
复制代码
|
|