【Error】IOError: [Errno 22] invalid mode ('wb') or filename
错误描述:
IOError: [Errno 22] invalid mode ('wb') or filename: 'C:\\Users\\Viral Patel\\Documents\\GitHub\\3DPhotovoltaics\\Data_Output\\Simulation_Data\\Raw_Data\\Raw_Simulation_Data_2014-03-24 17:21:20.545000.csv'
解决方案:
这个主要是文件名、路径中含有反转字符,具体请参照Naming Files, Paths, and Namespaces,路径中不要包含以下字符:
<(less than)>(greater than):(colon)"(double quote)/(forward slash)\(backslash)|(vertical bar or pipe)?(question mark)*(asterisk)
两种解决方式:
使用原生字符串
r'path\regionlog.txt'
去掉这些字符
#coding: utf-8 import re str1 = u'###现在开始,PM2.5小#米4 已经降到1299元! <a href="http://weibo.cn/sinaurl?f=w&u=http%3A%2F%2Ft.cn%2FRAJVndT&ep=D1Kpp8vLx%2C1749127163%2CD1Kpp8vLx%2C1749127163">http://t.cn/RAJVndT</a>'
str2 = u'【设计之美,美到不可%%思议】彩虹五号\n电池,采用\日本Maxell 电池核芯,电量充足,而且是碱性环保电池,无汞无镉,每盒十节才 9.9元,送收纳盒。小米网现货 <a href="http://weibo.cn/sinaurl?f=w&u=http%3A%2F%2Ft.cn%2FRzlIR1U&ep=D1lQnDS5B%2C1749127163%2CD1lQnDS5B%2C1749127163">http://t.cn/RzlIR1U</a>'
str3 = u'【小米电视3 新增55英寸,仅3999元】原装LG/三星屏真4K,全金属机身薄至9.9mm, 旗舰处理器,配MEMC运动图像补偿芯片,标配独立音响。【小米盒子3】全新升级64位4K网络机顶盒,标配小米蓝牙语音体感遥控,仅299元。'
str4 = u'小米生态链企业Ninebot CEO<a href="/n/%E9%AB%98%E7%A6%84%E5%B3%B0">@高禄峰</a> 告诉我,九号平衡车,截至现在预约量已突破40万台。大家别忘了明天首发,现在预约 <a href="http://weibo.cn/sinaurl?f=w&u=http%3A%2F%2Ft.cn%2FRzlIR1U&ep=D20GP9Zio%2C1749127163%2CD20GP9Zio%2C1749127163">http://t.cn/RzlIR1U</a>'
str5 = u'小米优惠多得数不清,力度也是空前的,我请同事整理一份完整的优惠清单供大家参考……'
str6 = u'<a href=/n/E69D8EE5ADA6E5878C>@李学凌</a> 试玩九号平衡车第一次就搞定他说广告词应该改成零秒上手挤眼'
str7 = u'原创】国产 5 P 聚会,人齐了就正式开始吧~(第二部)【37P】' pattern = re.compile('(<a href=\\S+</a>)|(@\\S+)') #content = weibo['content'].replace('http://', '!#$%&')\
# .split('//')[0].replace('!#$%&', 'http://')\
# .strip()
#content = pattern.sub('', weibo['content']).split('//', 1)[0].strip()
punct = set(u''':!),:;?]}¢'"、。〉》」』】〕〗〞︰︱︳/\ ﹐、#$%&
﹔﹕﹖﹗﹚﹜﹞!),:;?|}︴︶︸︺︼︾﹀﹂﹄﹏、~¢
々‖•·ˇˉ―--′’”([{£¥'"‵〈《「『【〔〖([{£¥〝︵︷︹︻
︽︿﹁﹃﹙﹛﹝({“‘-—_…''') # 对str/unicode
filterpunt = lambda s: ''.join(filter(lambda x: x not in punct, s))
#print pattern.sub('', str6)
print filterpunt(pattern.sub('', str2)).strip()
print filterpunt(str7).strip()
参考###
- https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
- http://stackoverflow.com/questions/15141761/region-ioerror-errno-22-invalid-mode-w-or-filename
- http://stackoverflow.com/questions/22620965/ioerror-errno-22-invalid-mode-wb-or-filename
【Error】IOError: [Errno 22] invalid mode ('wb') or filename的更多相关文章
- 【Error】IOError: [Errno 22] invalid mode
使用python打开或写入文件时会报以下错误IOError: [Errno 22] invalid mode,比如打开f:\nnpm.txt时,可以在地址前面加上r或R,即r'f:\nnpm.txt' ...
- Python报错IOError: [Errno 22] invalid mode ('r') or filename
IOError: [Errno 22] invalid mode ('r') or filename: 这种错误的出现是在使用built-in函数file()或者open()的时候. 或者是因为文件的 ...
- IOError: [Errno 22] invalid mode ('rb') or filename: 'F:\netData1.mat'
这种错误的出现是在使用built-in函数file()或者open()的时候.或者是因为文件的打开模式不对,或者是文件名有问题.前者的话只需要注意文件是否可读或者可写就可以了.后者则是与文件路径相关的 ...
- IOError: [Errno 22] invalid mode ('rb') or filename: 'C
dataset = scipy.io.loadmat('F:\test_data.mat') 报错 IOError: [Errno ] invalid mode ('rb') or filename: ...
- python IOError: [Errno 22] invalid mode ('r') or filename:
如果你是报这个错误,可能是因为你的文件路径中的中文字符太多的缘故. 你可以将路径或者文件名称改为英文试试.
- Python IOError: [Errno 22] invalid mode ('r') 解决方法
环境 Anaconda3 Python 3.6, Window 64bit 书籍 O'Reilly出版的Wes McKinney编的<Python for Data Analysis> r ...
- Python tarfile模块解压报错 invalid mode ('wb') or filename
问题原因 在使用tarfile模块解压一份Linux服务器上的打包文件时, 出现了错误提示: IOError: [Errno 22] invalid mode ('wb') or filename. ...
- 【Selenium】【BugList9】windows环境,fp = open("./"+ time.strftime("%Y-%m-%d %H:%M:%S") + " result.html",'wb'),报错:OSError: [Errno 22] Invalid argument: './2018-09-05 10:29:32 result.html'
[代码] if __name__=="__main__": suite = unittest.TestSuite() suite.addTest(Baidu("test_ ...
- python使用open的OSError: [Errno 22] Invalid argument错误
这两天在写一个新闻类的spider时,遇到了OSError: [Errno 22] Invalid argument这个错误,苦恼的两天,无果.后来通过请教学长,发现原来是打开的文件名中含有一些系统的 ...
随机推荐
- 19. Remove Nth Node From End of List(移除倒数第N的结点, 快慢指针)
Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...
- CSS中定义a:link、a:visited、a:hover、a:active顺序
a :link.a:hover.a:visited这几个元素,定义CSS时候的顺序不同,也会直接导致链接显示的效果不同. eg:让未访问链接颜色为red,活动链接为yellow,已访问链接为green ...
- git 移除某个文件的版本管理
1:最简单的,在项目刚创建的时候,在根目录的.gitignore,加入该文件的相对路径 2:已经被纳入到了版本控制,使用在当前目录下,打开cmd窗口 输入rm命令,加上文件的绝对路径(相对路径没试过) ...
- ABP官方文档翻译 1.6 OWIN集成
OWIN集成 安装 使用 如果在应用程序里既使用ASP.NET MVC也使用ASP.NET Web API,需要在工程里安装Abp.Owin包. 安装 添加Abp.Owin包到主工程里(一般是web工 ...
- node异步流程控制async
1.串行无关联:async.series(tasks,callback); 多个函数依次执行,之间没有数据交换,其中一个函数出错,后续函数不再执行 async.series({ one: functi ...
- Python3.x:chrome运行webdriver脚本提示--ignore-certificate-errors
Python3.x:chrome运行webdriver脚本提示--ignore-certificate-errors 1,分析原因: 根本原因是Chromedriver和Chrome的版本不兼容: 网 ...
- hadoop yarn HA集群搭建
可先完成hadoop namenode HA的搭建:http://www.cnblogs.com/kisf/p/7458519.html 搭建yarnde HA只需要在namenode HA配置基础上 ...
- 转载:vsftp中的local_umask和anon_umask
转载出处:http://blog.sina.com.cn/s/blog_67c5699001010e3e.html umask是unix操作系统的概念,umask决定目录和文件被创建时得到的初始权限u ...
- (转)国内yum源的安装(163,阿里云,epel)
国内yum源的安装(163,阿里云,epel) ----阿里云镜像源 1.备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS ...
- 20145301 实验三 "敏捷开发与XP实践"
20145301 实验三 "敏捷开发与XP实践" 课程:Java程序设计 班级:1453 指导教师:娄嘉鹏 实验日期:2016.04.22 实验名称:敏捷开发与XP实践 一.实验 ...