报错:SyntaxError: unexpected character after line continuation character的解决方法
Posted on 2020-06-23 11:39 Alex_bd 阅读(39043) 评论(0) 编辑 收藏 举报1 2 3 4 5 6 7 8 9 | if opt.freeze_layers: output_layer_indices = [idx - 1 for idx, module in enumerate (model.module_list) \ if isinstance (module, YOLOLayer)] freeze_layer_indices = [x for x in range ( len (model.module_list)) if \ (x not in output_layer_indices) and \ (x - 1 not in output_layer_indices)] for idx in freeze_layer_indices: for parameter in model.module_list[idx].parameters(): parameter.requires_grad_( False ) |
注意:上面的代码表面看起来没有问题,但是报错:SyntaxError:unexpected character after line continuation character 。
这里出现问题的原因是:
第一行的换行符“\” 后面存在空格。当换行符后面存在空格时,程序就会报错。
解决方法:
很简单,就把换行符“\” 后面的空格都删掉,问题就解决了。
也就是说,换行符后面是不允许再存在其他东西的。 包括 注释#
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步