• 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,产生原始字符串即可。

    我不断的寻找
  • 相关阅读:
    hoj 13832 Fence
    hoj 13830 DNA Sequencing 字典树
    HOJ Funfair
    HOJ 13828 Funfair
    图论相关
    01字典树
    异或
    日常补题2017-10-31
    康拓展开
    日常训练17-10-27(16杭州ccpc)
  • 原文地址:https://www.cnblogs.com/yNds/p/5396173.html
Copyright © 2020-2023  润新知