• Pycharm错误提示


    #coding:utf-8
    
    
    def test_file():
        f=codecs.open('C:UsersjohnDesktop11.txt','r+',encoding='utf-8')
        # content=f.read()
        f.write(u"测试information")
        f.close()
    
    test_file()
    

      错误提示:

    "D:Program Files (x86)Python 2.7.11python.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:UsersjohnDesktop11.txt','r+',encoding='utf-8')
      File "D:Program Files (x86)Python 2.7.11libcodecs.py", line 896, in open
        file = __builtin__.open(filename, mode, buffering)
    IOError: [Errno 22] invalid mode ('r+b') or filename: 'C:\Users\john\Desktop	.txt'
    

      也是被这编译器坑哭了,好几次的编译结果压根就不是当前的。

      修改后的错误代码:

      

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

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

      python中‘xx'编码格式为utf-8,形成了字符转义,必须用\,也可在字符串前加r,产生原始字符串即可。

    我不断的寻找
  • 相关阅读:
    【项目】项目225
    【原创】如何带格式转载博客园文章或其他网站的文章
    【项目】项目226
    【项目】项目229
    【项目】项目223
    【项目】项目230
    【项目】项目227
    如何带格式转载博客园文章或其他网站的文章
    Thread.Sleep(0)真的是bug吗?
    14.redis的慢日志
  • 原文地址:https://www.cnblogs.com/yNds/p/5396173.html
Copyright © 2020-2023  润新知