[英]Python Error EOL while scanning string literal from sample script
I'm doing some network programming code learning using sample script and running into an error when execute the script.我正在使用示例脚本进行一些网络编程代码学习,并在执行脚本时遇到错误。 This is the function related
这是相关的功能
def calculateCost(data,rate):
cost = 0
if rate=='tx':
transmitted = int(data["node-connector"][0]["opendaylight-port-statistics:flow-capable-node-connector-statistics"]["packets"]["transm$
cost = transmitted
elif rate=='rx':
received = int(data["node-connector"][0]["opendaylight-port-statistics:flow-capable-node-connector-statistics"]["packets"]["received$
cost = received
return cost
return error below下面返回错误
File "main.py", line 26
transmitted = int(data["node-connector"][0]["opendaylight-port-statistics:flow-capable-node-connector-statistics"]["packets"]["transm$
^
SyntaxError: EOL while scanning string literal
I noticed the line missing some bracket and quotn mark...but not sure if that is the problem... perhaps you guyz can help and advise me to correct it.我注意到该行缺少一些括号和 quotn 标记......但不确定这是否是问题......也许你们可以帮助并建议我纠正它。 Thank you for your help.
感谢您的帮助。
In python, a string in double quotes ( "
) cannot span more than one line. To do that you need to use triple quotes like: """foo bar""". In your case, at the end of the line beginning with transmitting
it looks like the code got cut off where the $
sign is, so it is missing the closing "
.在 python 中,双引号 (
"
) 中的字符串不能跨越多行。为此,您需要使用三重引号,例如:"""foo bar"""。在您的情况下,在行尾以transmitting
它看起来代码在$
符号所在的位置被切断,所以它缺少结束"
。 This is true on the seventh line as well.在第七行也是如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.