[Python-ideas] `to_file()` method for strings

Steven D'Aprano steve at pearwood.info
Wed Mar 23 07:48:40 EDT 2016


On Wed, Mar 23, 2016 at 12:40:56AM -0400, Alexander Belopolsky wrote:
> On Wed, Mar 23, 2016 at 12:33 AM, Chris Angelico <rosuav at gmail.com> wrote:
> 
> > >>     with tempfile.NamedTemporaryFile('w', dir=os.path.dirname(path),
> > ..
> > It's specifically selecting a directory for the temp file, so it ought
> > to work.
> 
> 
> I did not notice this.  Thanks, Chris.  Still not all filesystems do rename
> atomically.

I don't think that Python can guarantee to do more than the file system. 
The best Python can do is promise to do an atomic write if the OS and 
file system support it, otherwise to be no worse than what the OS and 
file system support.



-- 
Steve


More information about the Python-ideas mailing list