本文介绍了创建长文件时,Python IOError异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试使用"open(fname,'w +')"打开新文件时,出现如下所示的IOError.完整的错误消息如下.

I get an IOError shown below when trying to open a new file using "open (fname, 'w+')". The complete error message is below.

该文件不存在,但是我使用"os.access(dir_name,os.W_OK)"和"os.path.exists(dir_name)"验证了该文件的父目录确实存在.

The file does not exist, but I verified using "os.access(dir_name, os.W_OK)" and "os.path.exists (dir_name)" that the parent directory for the file does exist.

我想知道文件名对于Windows是否太长,或者我做错了什么.任何提示将不胜感激.非常感谢.

I am wondering if the file name is just too long for Windows, or if I am doing something wrong. Any tips would be appreciated. Thank you very much.

错误消息:

推荐答案

在Windows API中,最大路径长度限制为260个字符.

In the Windows API the maximum path length is limited to 260 characters.

http://msdn.microsoft. com/en-us/library/aa365247%28v = vs.85%29.aspx

更新:在路径前面加上"\\?\".

Update: prepend "\\?\" to the path.

这篇关于创建长文件时,Python IOError异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 13:12