我使用 JSON 來制作 .txt 檔案,但是當我用它來制作它們時
with open("Saves/" setname ".txt", "w") as savefile:
json.dump(data, savefile)
...我明白了:
Traceback (most recent call last):
File "c:\Users\creep\OneDrive\Bureaublad\Oyunlar\Retraich\main.py", line 647, in <module>
new_save()
File "c:\Users\creep\OneDrive\Bureaublad\Oyunlar\Retraich\main.py", line 448, in new_save
with open("Saves/" setname ".txt", "w") as savefile:
OSError: [Errno 22] Invalid argument: 'Saves/hello\r.txt'
我嘗試將它們設定在一個函式中。沒有代碼也在檔案名中添加 \r (我認為這就是錯誤的來源)。我嘗試將它們設定在定義函式中,但仍然無法正常作業。并且 setname 變數是 Hello
uj5u.com熱心網友回復:
setname被初始化為"hello\r"。回車 ( \r) 不是 Windows 檔案路徑中的有效字符。您可以通過修剪字串中的無效代碼點來避免這種情況:
setname = setname.strip("<>:\"\\/|?*\r\n")
Naming Conventions
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/504574.html
上一篇:建立TCP服務端
