Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
same context functions
#7
you know the builtin function locals(). i could pass that to a function instead of passing a whole bunch of variables and getting a whole bunch of them back. i'd just need to code all the accesses in the functions as dictionary accesses.

i wrote a function named caller_locals() that, for the caller of caller_locals(), caller_locals() returns it's caller's locals. so with that, i don't even need to pass locals() to those in-context functions.

from inspect import currentframe
def caller_locals():
    frame = currentframe()
    if not frame:return None
    frame = frame.f_back
    if not frame:return None
    frame = frame.f_back
    if not frame:return None
    return frame.f_locals
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
same context functions - by Skaperen - Jun-16-2019, 01:33 AM
RE: same context functions - by Yoriz - Jun-16-2019, 07:33 AM
RE: same context functions - by DeaD_EyE - Jun-16-2019, 09:40 AM
RE: same context functions - by Skaperen - Jun-16-2019, 06:26 PM
RE: same context functions - by Gribouillis - Jun-16-2019, 08:41 PM
RE: same context functions - by Skaperen - Jun-17-2019, 12:22 AM
RE: same context functions - by Skaperen - Jun-17-2019, 04:05 AM
RE: same context functions - by Gribouillis - Jun-17-2019, 06:37 AM
RE: same context functions - by Skaperen - Jun-17-2019, 05:35 PM
RE: same context functions - by Gribouillis - Jun-17-2019, 08:36 PM
RE: same context functions - by Skaperen - Jun-18-2019, 05:09 AM
RE: same context functions - by Gribouillis - Jun-18-2019, 05:43 AM
RE: same context functions - by Skaperen - Jun-18-2019, 06:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  exception context Skaperen 0 2,392 Mar-06-2021, 08:42 PM
Last Post: Skaperen
  function to store in caller's context Skaperen 7 3,215 Jul-27-2020, 08:45 PM
Last Post: Skaperen
  turning my function into a context manager Skaperen 2 2,071 Nov-14-2019, 09:08 PM
Last Post: Skaperen
  i want to make my own context manager Skaperen 0 1,755 Nov-10-2019, 05:21 AM
Last Post: Skaperen
  Windows Context Menu Depth GWild 0 2,383 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