Python Forum
turning my function into a context manager
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
turning my function into a context manager
#1
i have a function named "cd()". called with a directory name, it changes the process current working directory to that directory. called with no argument or None, it changes the process current working directory to the user home directory. i'm thinking of adding __enter__() and __exit__() so it can be a context manager on the with statement. on entry, it will save the current working directory before changing to the specified directory. on exit, it will restore the previous directory. i'm sure this has been done before, but i was re-reading PEP 343 again, tonight (a little slower this time).

i'm going through my other functions ("Skaperen's Function Collection") to see what else might be doable (and maybe useful, maybe not).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
turning my function into a context manager - by Skaperen - Nov-14-2019, 05:43 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  exception context Skaperen 0 2,377 Mar-06-2021, 08:42 PM
Last Post: Skaperen
  function to store in caller's context Skaperen 7 3,155 Jul-27-2020, 08:45 PM
Last Post: Skaperen
  i want to make my own context manager Skaperen 0 1,724 Nov-10-2019, 05:21 AM
Last Post: Skaperen
  same context functions Skaperen 12 5,535 Jun-18-2019, 06:09 PM
Last Post: Skaperen
  Windows Context Menu Depth GWild 0 2,365 Jan-27-2018, 07:18 AM
Last Post: GWild

Forum Jump:

User Panel Messages

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