Windows系统下,此异常在以'a+'模式打开文件,读文件,再写入过程中出现。其原因在于读写交替过程中必须要有fflush, fseek, fsetpos, rewind这类操作,不然python就不知道当前文件位置在哪啦。最笨的办法就是在关闭文件前只做读或者写一种操作,省心

一点的方法是在写入文件前用fseek(),或者fsetpos()设定插入文本的位置。

f.seek(offset [, whence]) whence 为0表示当前文件位置在文件开头,1表示在上次read后的地方,2表示文件末尾。offset为偏移量。

要避免出现此异常,在写入文件前加上

f.seek(0,2)

即可。

参考资料:http://stackoverflow.com/a/11176772

python IOError: [Errno 0] Error的更多相关文章

  1. Python 读文件:IOError: [Errno 0] Error

    Windows系统下,这种情况发生在读取文件,再写入过程中出现. 原因是读完文件后python不知道当前文件位置在哪里. 方法一是:在关闭文件前只做读或者写一种操作. 方法二是:在写入文件前使用fil ...

  2. [爬虫]爬虫时碰到的IOError: [Errno ftp error] [Errno 10060]错误的原因以及解决方法

    IOError: [Errno ftp error] [Errno 10060] 原因是爬取页面过快造成暂时被网站ban掉的情况,设置time.sleep(1)就好,后来发现ban的时间不定,就自己动 ...

  3. Python IOError: [Errno 22] invalid mode ('r') 解决方法

    环境 Anaconda3 Python 3.6, Window 64bit 书籍 O'Reilly出版的Wes McKinney编的<Python for Data Analysis> r ...

  4. urllib 报错 IOError: [Errno socket error] TLS/SSL connection has been closed (EOF) (_ssl.c:590)

    解决方案: My evil workaround (don't do this in production!): import urllib2 #也可以是urllib import ssl ctx = ...

  5. python IOError: [Errno 22] invalid mode ('r') or filename:

    如果你是报这个错误,可能是因为你的文件路径中的中文字符太多的缘故. 你可以将路径或者文件名称改为英文试试.

  6. Python IOError: [Errno 13] Permission denied:

    一般是代码写错了,比如我遇到的问题就是由于 os.listdir() 传参传错导致的. 本应该传入字符串路径名,但传入了一个文件对象(object)

  7. linux系统中errno与error对照表

    1.使用了一个小程序输出所有的errno对应的error字符串,代码如下 #include <errno.h> void showError(int err){ printf(" ...

  8. windows python flask上传文件出现IOError: [Errno 13] Permission denied: 'E:\\git\\test\\static\\uploads'的解决方法

    在浏览器中输入时,出现IOError: [Errno 13] Permission denied: 'E:\\git\\test\\static\\uploads' http://127.0.0.1: ...

  9. Fix Python 3 on Windows error Microsoft Visual C++ 14.0 is required

    Fix Python 3 on Windows error Microsoft Visual C++ 14.0 is required Fix the error for Python 3.6 and ...

随机推荐

  1. javascript中怎么判断对象{}为空

    有时候通过AJAX方法调用返回的是一个JSON对象,而这个对象可能在开发过程中会没有数据是一个空{}. JavaScript判断object/json 是否为空,可以使用jQuery的isEmptyO ...

  2. 求1...n中因子最多的数

    Problem 求[1..N]中素因子数最多且最小的数n,N充分大. Solution 将任意自然数n (n>2) 分解 n=p1^k1 * p2^k2 * p3^k3 * ... * Pm^k ...

  3. 配置linux----------------ip

    在终端中输入 vi /etc/sysconfig/network-scripts/ifcfg-eth0 =================================== DEVICE=" ...

  4. Traditional Language Model

    Traditional Language Model通常用于回答下述问题: How likely is a string of English words good English ? \(p_{LM ...

  5. 树莓派笔记之使用netselect选择最快Raspbian软件源

    背景: 之前在葉難大大的部落格里看到有讲可以使用netselect查找最快软件源,今天正好看到, 特此记下来,因为之前一直使用中国科学技术大学的源,结果发现不是我这里最快的. 注意: 以下仅对Rasp ...

  6. 树莓派2安装使用小米WIfi(360 小度 腾讯wifi)

    更新2015年11月16日,jessie内核版本号4.1.13(uname -a 可以查看)直接可以驱动MT7601U,无需手动编译. 截止2015-4-6,本文基于树莓派2,raspbian,内核版 ...

  7. 面试题目——《CC150》高等难题

    面试题18.1:编写一个函数,将两个数字相加.不得使用+或其他算数运算符. package cc150.high; public class Add { public static void main ...

  8. Protecting against XML Entity Expansion attacks

    https://blogs.msdn.microsoft.com/tomholl/2009/05/21/protecting-against-xml-entity-expansion-attacks/ ...

  9. 写JSP文件遇到的一个问题

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  10. 笨办法学Python (exercise1-15)

    #exercise1print "Hello world!"print "Hello Again"print "I like typing this. ...