如题,在使用python语言的open函数时,提示错误OSError: [Errno 22] Invalid argument: ‘文件路径’,在查阅了大量资料后也得到了一些解决方案,但是这些解决方案对于作者的情况都不适用,依然报错,没办法,虽然作者的英语水平很不咋地,但中文帮不了作者,只好求助于英文了。

       建议各位看客在修改时,仔细看清楚自己的情况是否适用。废话不多说,开始正文。

       作者的路径为open(‘D:\LearningBooks\test.txt’)

       在使用时报错是因为这个路径是直接从Windows的文件目录里复制过来的,在python中\是转义字符,作者文件中的\test.txt中,\t是制表字符,要想正常使用路径需要改成如下形式D:\LearningBooks\\test.txt,或者r‘D:\LearningBooks\test.txt’

       或者D:/LearningBooks/test.txt即直接用斜杠/不用反斜杠\

       这一点其实在多个语言中都很重要,写下此文主要是提醒自己一定要注意路径的书写规范。

转自:https://blog.csdn.net/qq_33363973/article/details/77862007

在使用python语言的open函数时,提示错误OSError: [Errno 22] Invalid argument: ‘文件路径’的更多相关文章

  1. python使用open的OSError: [Errno 22] Invalid argument错误

    这两天在写一个新闻类的spider时,遇到了OSError: [Errno 22] Invalid argument这个错误,苦恼的两天,无果.后来通过请教学长,发现原来是打开的文件名中含有一些系统的 ...

  2. python OSError: [Errno 22] Invalid argument: 'D:\\crawle\x01.html1'

    import urllib.request file = urllib.request.open("http://www.baidu.com") data = file.read( ...

  3. 【Selenium + Python】路径报错之OSError: [Errno 22] Invalid argument: './t/report/2018-03-23_11:03:12_report.html'

    现象: 此问题真的是太痛苦了,查了好多资料是说路径的问题,结果还是报错,后来一点点的排查才发现原来是!!!!!! 废话不多说上原来代码: if __name__ == '__main__': star ...

  4. python OSError: [Errno 22] Invalid argument: '\u202aF://text

    windows10 python3 读文件的时候报的错误 原因不明时好时坏很头疼但又没办法不知道怎么解决,网上的说法都不能解决,

  5. Python创建文件报错OSError:[Errno 22] Invalid argument处理

    问题: windows平台下使用python open函数w模式打开文件报错“OSError: [Errno 22] Invalid argument: '../news/“消费升维”成零售业新风口? ...

  6. 提交时提示错误This Bundle is invalid.New apps and app updates submitted to the App Store must be built wit

    this bundle is invalid . new apps and app updates submitted to the app store must be built with publ ...

  7. Python报错IOError: [Errno 22] invalid mode ('r') or filename

    IOError: [Errno 22] invalid mode ('r') or filename: 这种错误的出现是在使用built-in函数file()或者open()的时候. 或者是因为文件的 ...

  8. Oracle登录时提示错误,导致用户无法登录

    Oracle登录时提示错误,导致用户无法登录,错误如下 ------------------------------------------------------------------------ ...

  9. Ubuntu 使用apt-get时提示错误:无法获得锁 /var/lib/dpkg/lock

    推荐博客:http://blog.sina.com.cn/s/blog_5c1450a8010188ju.html Ubuntu 使用apt-get时提示错误:无法获得锁 /var/lib/dpkg/ ...

随机推荐

  1. 57 CUDA 编程入门

    0 引言 由于毕设用到了Marvin,采用的是CUDA框架作为加速器,正好借此学习一下CUDA编程的一些基本知识. 各个版本的cuda的下载链接如下. https://developer.nvidia ...

  2. hexo next主题深度优化(六),使用hexo-neat插件压缩页面,大幅度提升页面性能和响应速度。

    文章目录 隆重感谢: 背景 开始 试水 成功的案例 安装插件,执行命令. hexo _config.yml文件添加 坑 跳过压缩文件的正确配置方式 压缩html时不要跳过.md文件 压缩html时不要 ...

  3. CometOJ Contest #3 C

    题目链接:https://cometoj.com/contest/38/problem/C?problem_id=1542&myself=0&result=0&page=1&a ...

  4. PAT_A1004#Counting Leaves

    Source: PAT A1004 Counting Leaves (30 分) Description: A family hierarchy is usually presented by a p ...

  5. sails中创建和使用services

    从sails官方在线文档查知 // EmailService.js - in api/services module.exports = { sendInviteEmail: function(opt ...

  6. pyhton2与python3的使用区别

    刚刚开始学习python这门编程语言,考虑到python不同版本的一些用法不同,收集整理了一份python2与python3之间的区别,目前可能不全 编码(核心类) Python2默认编码ascii, ...

  7. swt java 内嵌ActiveX控件

    这里用的是SWT/JFace开发application中SWT自带的org.eclipse.swt.ole.win32 包可以支持内嵌OLE和ActiveX. 具体用法如下: //创建一个OleFra ...

  8. vue 父子组件、兄弟组件传值

    参考文章:Vue2.0子同级组件之间数据交互 1.父组件可以使用 props 把数据传给子组件.2.子组件可以使用 $emit 触发父组件的自定义事件. (一)父组件给子组件传值,关键字:props ...

  9. C++ BASS 实例

    #include <iostream> #include <string> #include <map> #include "..\sdk\bass\in ...

  10. Hibernate与数据库交互方式和Hibernate常用的几个方法

    第一种,适合sql语言水平比较高的人用 HQL(Hibernate Query Language) 面向对象的查询语言,与SQL不同,HQL中的对象名是区分大小写的(除了JAVA类和属性其他部分不区分 ...