zoukankan      html  css  js  c++  java
  • 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,产生原始字符串即可。

    我不断的寻找
  • 相关阅读:
    生产者消费者模式 (在已有线程下不断生产不断消费)
    Spring boot Spring cloud 框架搭建
    个人见解
    加入博客园!
    sqlserver 工具
    slqserver 拆分函数
    sqlserver 自定义函数与存储过程的区别
    sqlserver row_number() over() 理解
    C# Newtonsoft.Json JObject移除属性
    PropertyInfo 简单用法
  • 原文地址:https://www.cnblogs.com/yNds/p/5396173.html
Copyright © 2011-2022 走看看