Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
with os.open?
#3
See also contextlib.contextmanager for a simplified interface and also contextlib.closing and the like
import contextlib

@contextlib.contextmanager
def my_open(*args, **kwargs):
    fd = os.open(*args, **kwargs)
    try:
        yield fd
    finally:
        os.close(fd)

with my_open(my_thing) as desc:
    ...
Reply


Messages In This Thread
with os.open? - by Skaperen - May-28-2019, 10:04 PM
RE: with os.open? - by heiner55 - May-29-2019, 03:12 AM
RE: with os.open? - by Gribouillis - May-29-2019, 07:22 AM
RE: with os.open? - by heiner55 - May-30-2019, 07:33 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020