IOError:[Errno 27] File too large
steve+comp.lang.python at pearwood.info
Wed Mar 13 18:32:59 CET 2013
On Wed, 13 Mar 2013 09:53:17 -0700, ch.valderanis wrote:
> Relatively newcomer here.
> The following code fails with the above error: python version used 2.6.2
> under linux
Which part of the code fails? Please copy and paste the entire traceback,
starting with the line "Traceback (most recent call last)" and ending
with the complete error message.
Which file does it fail on?
> for files in glob.glob('*'):
Some other comments:
You use the name "files" to represent a single filename, rather than
multiple files. That is misleading, a poor choice of name.
"f2" is also a poor name.
You try to change the file extension using string.replace method. This is
risky, and will fail if some file has ".xml" in the filename apart from
the file extension. Worse, if you have a file *without* ".xml", your code
will over-write that file. Better to use the os.path.splitext function
Is filestring really a constant string like in the snippet above? Is
there any change that it could be an enormous string?
Re-writing your code snippet:
filestring = 'somestring'
for filename in glob.glob('*.xml'):
newname = os.path.splitext(filename) + '.sub'
newfile = open(newname, 'w')
newfile.write(filestring + filename)
> I am pretty sure that the files is less than 1kB.
"Pretty sure"? You need to be 100% certain. We can't tell you whether
this is the case or not.
> Is there another reason for the operation to fail?
We don't know which operation has failed. That's why you need to show the
More information about the Python-list