[Python-Dev] Re: NamedTemporaryFile and context managers

2021-04-09 Thread Serhiy Storchaka
08.04.21 23:31, Ethan Furman пише: > In issue14243 [1] there are two issues being tracked: > > - the difference in opening shared files between posix and Windows > - the behavior of closing the underlying file in the middle of >   NamedTemporaryFile's context management > > I'd like to address an

[Python-Dev] Re: NamedTemporaryFile and context managers

2021-04-08 Thread Ivan Pozdeev via Python-Dev
On 08.04.2021 23:31, Ethan Furman wrote: In issue14243 [1] there are two issues being tracked: - the difference in opening shared files between posix and Windows - the behavior of closing the underlying file in the middle of  NamedTemporaryFile's context management I'd like to address and get

[Python-Dev] Re: NamedTemporaryFile and context managers

2021-04-08 Thread Eric V. Smith
On 4/8/2021 4:43 PM, Antoine Pitrou wrote: On Thu, 8 Apr 2021 13:31:26 -0700 Ethan Furman wrote: ```python from tempfile import NamedTemporaryFile with NamedTemporaryFile() as fp: fp.write(b'some data') fp.close() # Windows workaround fp.open() data = fp.read() assert

[Python-Dev] Re: NamedTemporaryFile and context managers

2021-04-08 Thread Rob Cliffe via Python-Dev
Well this works: from tempfile import NamedTemporaryFile import os with NamedTemporaryFile(delete=False) as fp:   fp.write(b'some data')   fp.close()   with open(fp.name, 'rb') as fp2:     data = fp2.read()   os.remove(fp.name) assert data == b'some data' Of course it is

[Python-Dev] Re: NamedTemporaryFile and context managers

2021-04-08 Thread Ethan Furman
On 4/8/21 1:43 PM, Antoine Pitrou wrote: On Thu, 8 Apr 2021 13:31:26 -0700 Ethan Furman wrote: ```python from tempfile import NamedTemporaryFile with NamedTemporaryFile() as fp: fp.write(b'some data') fp.close() # Windows workaround fp.open() data = fp.read() assert

[Python-Dev] Re: NamedTemporaryFile and context managers

2021-04-08 Thread Ronald Oussoren via Python-Dev
> On 8 Apr 2021, at 22:31, Ethan Furman wrote: > > In issue14243 [1] there are two issues being tracked: > > - the difference in opening shared files between posix and Windows > - the behavior of closing the underlying file in the middle of > NamedTemporaryFile's context management > > I'd l

[Python-Dev] Re: NamedTemporaryFile and context managers

2021-04-08 Thread Antoine Pitrou
On Thu, 8 Apr 2021 13:31:26 -0700 Ethan Furman wrote: > > ```python > from tempfile import NamedTemporaryFile > > with NamedTemporaryFile() as fp: > fp.write(b'some data') > fp.close() # Windows workaround > fp.open() > data = fp.read() > > assert data == 'some_data' > ```