在使用python语言的open函数时,提示错误OSError: [Errno 22] Invalid argument: ‘文件路径’
如题,在使用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: ‘文件路径’的更多相关文章
- python使用open的OSError: [Errno 22] Invalid argument错误
这两天在写一个新闻类的spider时,遇到了OSError: [Errno 22] Invalid argument这个错误,苦恼的两天,无果.后来通过请教学长,发现原来是打开的文件名中含有一些系统的 ...
- python OSError: [Errno 22] Invalid argument: 'D:\\crawle\x01.html1'
import urllib.request file = urllib.request.open("http://www.baidu.com") data = file.read( ...
- 【Selenium + Python】路径报错之OSError: [Errno 22] Invalid argument: './t/report/2018-03-23_11:03:12_report.html'
现象: 此问题真的是太痛苦了,查了好多资料是说路径的问题,结果还是报错,后来一点点的排查才发现原来是!!!!!! 废话不多说上原来代码: if __name__ == '__main__': star ...
- python OSError: [Errno 22] Invalid argument: '\u202aF://text
windows10 python3 读文件的时候报的错误 原因不明时好时坏很头疼但又没办法不知道怎么解决,网上的说法都不能解决,
- Python创建文件报错OSError:[Errno 22] Invalid argument处理
问题: windows平台下使用python open函数w模式打开文件报错“OSError: [Errno 22] Invalid argument: '../news/“消费升维”成零售业新风口? ...
- 提交时提示错误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 ...
- Python报错IOError: [Errno 22] invalid mode ('r') or filename
IOError: [Errno 22] invalid mode ('r') or filename: 这种错误的出现是在使用built-in函数file()或者open()的时候. 或者是因为文件的 ...
- Oracle登录时提示错误,导致用户无法登录
Oracle登录时提示错误,导致用户无法登录,错误如下 ------------------------------------------------------------------------ ...
- Ubuntu 使用apt-get时提示错误:无法获得锁 /var/lib/dpkg/lock
推荐博客:http://blog.sina.com.cn/s/blog_5c1450a8010188ju.html Ubuntu 使用apt-get时提示错误:无法获得锁 /var/lib/dpkg/ ...
随机推荐
- 53 windows 系统下
0 引言 本篇主要记录windows下编程以及系统安装与恢复等问题. 1 Visual Studio (1)debug "warning LNK4042: 对象被多次指定:已忽略多余的指定& ...
- python解决迅雷下载限制的方法
一.转换迅雷下载链接 import base64 url='thunder://QUFodHRwOi8veHVubGVpLnhpYXphaS16dWlkYS5jb20vMTkwOC/JqLa+Mi5I ...
- NX二次开发-C++的vector排序去重用法
#include <algorithm> //vector排序去重 sort( BoxNum.begin(), BoxNum.end()); BoxNum.erase(unique(Box ...
- Linux命令(2):cat
cat命令是一个文本连接和查看的命令,用于文件的输出显示. 三大功能 一次显示整个文件. $ cat filename 从键盘创建一个文件.只能创建新文件,不能编辑已有文件. $ cat > f ...
- hdu多校第五场1002 (hdu6625) three arrays 字典树/dfs
题意: 给你两个序列a,b,序列c的某位是由序列a,b的此位异或得来,让你重排序列ab,找出字典序最小的序列c. 题解: 如果能找到a,b序列中完全一样的值当然最好,要是找不到,那也尽量让低位不一样. ...
- Go中的switch fallthrough
Go基础 switch sExpr { case expr1: some instructions case expr2: some other instructions case expr3: ...
- JVM内核-原理、诊断与优化学习笔记(一):初识JVM
文章目录 JVM的概念 JVM是Java Virtual Machine的简称.意为Java虚拟机 虚拟机 有哪些虚拟机 VMWare或者Visual Box都是使用软件模拟物理CPU的指令集 JVM ...
- 使用反射机制,获取 ArrayList 的容量大小
本文所有说明及代码示例都是基于JDK 1.8 ArrayList 提供size()方法获取当前集合的元素数量,但无法知道当前集合的容量,翻看 ArrayList 的源代码,可以看到字段 elemen ...
- 《转》python 9 字典,numpy
http://www.cnblogs.com/BeginMan/p/3156960.html 一.映射类型 我理解中的映射类型是:键值对的关系,键(key)映射值(value),且它们是一对多的关系. ...
- jupyter安装_pip法
安装jupyter notebook的流程(注意python至少需要3.6版本) python -m pip install jupyter #安装jupyter python -m pip ins ...