0

Possible Duplicate:
Python code to get current function into a variable?

is there a convenient way to get to pointer of current function?

for example:

current_func_ref = None
def func():
    current_func_ref = ___ #something need to fill
    do something..
Community
  • 1
  • 1
Max
  • 7,957
  • 10
  • 33
  • 39
  • You want a reference to the current function being called on the stack? – jdi Aug 29 '12 at 04:47
  • 3
    What are you trying to do in the end? This is a very strange pattern for Python. – Burhan Khalid Aug 29 '12 at 05:12
  • note: `current_func_ref` inside the function creates a *local* name. It has no effect on `current_func_ref` at the outer level. – jfs Aug 29 '12 at 05:41

1 Answers1

0

Ok this is a bit cheeky, not very generic like you might want, but here it is anyway:

current_func_ref = None
def func():
    global current_func_ref
    current_func_ref = func
Daniel Kinsman
  • 536
  • 4
  • 7
  • when you change the functions name ,you also need to change the code. – Max Aug 29 '12 at 05:36
  • @user1544915 Yep, hence me describing it as cheeky and not generic. But like the other commentors have said, even wanting to do this in the first place is odd. What problem are you actually trying to solve? – Daniel Kinsman Aug 29 '12 at 05:45