Python_報錯:SyntaxError: EOL while scanning string literal


Python_報錯:SyntaxError: EOL while scanning string literal

原因:python中,目錄操作時,字符串的最后一個字符是斜杠,會導致出錯,去掉\即可

上代碼

>>> import os
>>> os.chdir(r"e:\")#字符串的最后一個字符是斜杠,會導致出錯
  File "<stdin>", line 1
    os.chdir(r"e:\")
                   ^
SyntaxError: EOL while scanning string literal

解決方法:去掉最后的\即可

>>> import os
>>> os.chdir(r"e:")
>>>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM