簡體   English   中英

從示例腳本掃描字符串文字時出現 Python 錯誤 EOL

[英]Python Error EOL while scanning string literal from sample script

我正在使用示例腳本進行一些網絡編程代碼學習,並在執行腳本時遇到錯誤。 這是相關的功能

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

下面返回錯誤

 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

我注意到該行缺少一些括號和 quotn 標記......但不確定這是否是問題......也許你們可以幫助並建議我糾正它。 感謝您的幫助。

在 python 中,雙引號 ( " ) 中的字符串不能跨越多行。為此,您需要使用三重引號,例如:"""foo bar"""。在您的情況下,在行尾以transmitting它看起來代碼在$符號所在的位置被切斷,所以它缺少結束" 在第七行也是如此。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM