在 2013年12月6日星期五UTC+8下午10时59分43秒,Chris Angelico写道:
> On Sat, Dec 7, 2013 at 1:54 AM, iMath <redstone-c...@163.com> wrote:
> 
> >     fp=tempfile.NamedTemporaryFile(delete=False)
> 
> >     fp.write(("file '"+fileName1+"'\n").encode('utf-8'))
> 
> >     fp.write(("file '"+fileName2+"'\n").encode('utf-8'))
> 
> >
> 
> >
> 
> >     subprocess.call(['ffmpeg', '-f', 'concat','-i',fp.name, '-c',  'copy', 
> > fileName])
> 
> >     fp.close()
> 
> 
> 
> You need to close the file before getting the other process to use it.
> 
> Otherwise, it may not be able to open the file at all, and even if it
> 
> can, you might find that not all the data has been written.
> 
> 
> 
> But congrats! You have successfully found the points I was directing
> 
> you to. Yes, I was hinting that you need NamedTemporaryFile, the .name
> 
> attribute, and delete=False. Good job!
> 
> 
> 
> ChrisA

we don't have permission to use the temporary file while it has not been 
closed,but when the file is closed , it will be destroyed by 
default(delete=True),but once we set delete=False,then we couldn't depend on 
the convenience of letting the temporary file automatically delete itself after 
it has been used(then we have to delete it later by os.remove()) ,thus there is 
nearly no convenience in creating a temporary file or a persistent one when 
using NamedTemporaryFile.

I think this is a design flaw and should be improved like this :when 
delete=True,the file should be removed upon destruction of the object or on 
function return or on garbage collected,only when delete=False,the file can 
remain on the disk .
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to