我對 Python 很陌生,所以我提前為我的愚蠢問題道歉。
我正在嘗試運行 這個應用程式
這是 Python 代碼:
def load_json(path):
with open(path, "r") as json_file:
data = json.load(json_file)
validate(instance=data, schema=schema)
return data
我按照所有步驟操作并認為我做的一切都是正確的,但是一旦我通過終端運行應用程式并提供所需資訊(客戶端 ID、客戶端密鑰和 Json 元資料的路徑),我就會收到此錯誤:
“<C:\Users\Administrator\Desktop\spotiminder-master\playlist.json> 不可讀。”
我嘗試更改 JSON 檔案的位置并重命名該檔案,但均未成功。我究竟做錯了什么?謝謝你。
uj5u.com熱心網友回復:
您正在嘗試在 "<C:\Users\Administrator\Desktop\spotiminder-master\playlist.json>"
但我認為,你的檔案在這里:"C:\Users\Administrator\Desktop\spotiminder-master\playlist.json"
洗掉<>你的路徑,它會作業
uj5u.com熱心網友回復:
觀察當我嘗試使用您在 IPython 會話中使用的檔案的路徑時會發生什么:
In [1]: path = "C:\Users\Administrator\Desktop\spotiminder-master\playlist.json"
File "<ipython-input-1-1980786d97e2>", line 1
path = "C:\Users\Administrator\Desktop\spotiminder-master\playlist.json"
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
在 Python 字串中\U具有特殊含義。它是 Unicode 轉義序列的開始。
嘗試使用以下檔案名(注意雙反斜杠): C:\\Users\Administrator\Desktop\spotiminder-master\playlist.json
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/412322.html
標籤:
上一篇:C 中的json配置閱讀器
