Python Forum
How to get parent directory from existing func not user func ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get parent directory from existing func not user func ?
#3
You can the parent of a function with inspect:

This combined with Nilamo's code could be the start of a useful way to create program flow graphically.

import inspect

def function1():
   print('Function1 called from: {}'.format(inspect.stack()[1][3]))

def function3():
   print('Function1 called from: {}'.format(inspect.stack()[1][3]))
   function1()

def function2():
   print('Function2 called from: {}'.format(inspect.stack()[1][3]))
   function3()

def main():
   function2()


if __name__ == '__main__':
   main()
results:
Output:
Function2 called from: main Function1 called from: function2 Function1 called from: function3 Process finished with exit code 0
Reply


Messages In This Thread
RE: How to get parent directory from existing func not user func ? - by Larz60+ - May-15-2017, 04:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I print from within actor(func) ?? Pedroski55 2 1,036 May-01-2024, 05:35 AM
Last Post: Pedroski55
  write code that resides in parent directory franklin97355 3 1,558 Apr-14-2024, 02:03 AM
Last Post: franklin97355
  How to output one value per request of the CSV and print it in another func? Student44 3 2,849 Nov-11-2022, 10:45 PM
Last Post: snippsat
  Func Animation not displaying my live graph jotalo 0 2,035 Nov-13-2020, 10:56 PM
Last Post: jotalo
  Trying to write func("abcd") -> "abbcccdddd" omm 8 6,355 Oct-24-2020, 03:41 AM
Last Post: bowlofred
  Getter/Setter : get parent attribute, but no Getter/Setter in parent nboweb 2 4,581 May-11-2020, 07:22 PM
Last Post: nboweb
  call func from dict mcmxl22 3 3,792 Jun-21-2019, 05:20 AM
Last Post: snippsat
  About [from FILE import FUNC] Nwb 7 5,267 Apr-21-2019, 02:46 PM
Last Post: snippsat
  Executing func() from a different folder ebolisa 2 3,151 Jan-14-2019, 10:18 AM
Last Post: ebolisa
  Correct number wrong position func. albry 5 7,524 Jan-11-2019, 04:01 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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