找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 2699|回复: 3

[求助] python定义函数 这个语法哪里有错误?

2

主题

3

帖子

3

积分

贫民

积分
3
xiop 发表于 2018-4-30 08:31:32 | 显示全部楼层 |阅读模式
本帖最后由 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的语法。

函数定义如下:
  1. def readCMFile(filePath):
  2.       """Read the file, so we can compute stats for video, category and overall."""
  3.           if not os.path.exists(filePath):
  4.                 print("The file " + filePath + " doesn't exist.\nIt means there was an error calling the comparator.")
  5.                 raise Exception('error');
  6.        
  7.     with open(filePath) as f:
  8.         for line in f.readlines():
  9.             if line.startswith('cm:'):
  10.                 numbers = line.split()[1:]
  11.                 return [int(nb) for nb in numbers[:5]]
复制代码


回复

使用道具 举报

0

主题

956

帖子

956

积分

圣骑士

积分
956
sheeboard 发表于 2018-4-30 09:19:38 | 显示全部楼层
windows还是linux,windows路径斜杠要转义
回复 支持 反对

使用道具 举报

2

主题

3

帖子

3

积分

贫民

积分
3
xiop  楼主| 发表于 2018-4-30 09:36:28 | 显示全部楼层
sheeboard 发表于 2018-4-30 09:19
windows还是linux,windows路径斜杠要转义

3x!

是windows环境下
回复 支持 反对

使用道具 举报

3

主题

278

帖子

278

积分

侠客

积分
278

热心会员

uitb 发表于 2018-5-1 16:19:42 | 显示全部楼层
本帖最后由 uitb 于 2018-5-1 16:21 编辑

明显的对齐问题嘛
  1.       """Read the file, so we can compute stats for video, category and overall."""
  2.           if not os.path.exists(filePath):
复制代码

这两行不是该同一个层级、该对齐的嘛?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表