Pycharm錯誤提示


#coding:utf-8


def test_file():
    f=codecs.open('C:\Users\john\Desktop\11.txt','r+',encoding='utf-8')
    # content=f.read()
    f.write(u"測試information")
    f.close()

test_file()

  錯誤提示:

"D:\Program Files (x86)\Python 2.7.11\python.exe" "D:/Program Files (x86)/Python 2.7.11/Lib/site-packages/Card/algorithm/string_test.py"
Traceback (most recent call last):
  File "D:/Program Files (x86)/Python 2.7.11/Lib/site-packages/Card/algorithm/string_test.py", line 100, in <module>
    test_file()
  File "D:/Program Files (x86)/Python 2.7.11/Lib/site-packages/Card/algorithm/string_test.py", line 80, in test_file
    f=codecs.open('C:\Users\john\Desktop\11.txt','r+',encoding='utf-8')
  File "D:\Program Files (x86)\Python 2.7.11\lib\codecs.py", line 896, in open
    file = __builtin__.open(filename, mode, buffering)
IOError: [Errno 22] invalid mode ('r+b') or filename: 'C:\\Users\\john\\Desktop\t.txt'

  也是被這編譯器坑哭了,好幾次的編譯結果壓根就不是當前的。

  修改后的錯誤代碼:

  

f=codecs.open('C:\\Users\\john\Desktop\\11.txt','r+',encoding='utf-8')

  -----------------------------------------

  python中‘\xx'編碼格式為utf-8,\形成了字符轉義,必須用\\,也可在字符串前加r,產生原始字符串即可。


免責聲明!

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



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