Name of function caller

H

HMS Surprise

Is there a way that a function may access the doc string or func_name
of the caller?

Thanks,

jvh
 
P

Paul McGuire

Is there a way that a function may access the doc string or func_name
of the caller?

Thanks,

jvh

Yes. The inspect module allows you to look up the call stack for
information on the caller, the caller's caller, local vars, etc.

-- Paul
 
H

HMS Surprise

Yes. The inspect module allows you to look up the call stack for
information on the caller, the caller's caller, local vars, etc.

-- Paul

Thanks Paul.

Running jython 2.2. No module named inspect or cInspect


drat...
 
J

John Machin

Thanks Paul.

Running jython 2.2. No module named inspect or cInspect

drat...

According to the current docs, inspect was new in Python 2.1. You've
been in more strife than Paris Hilton recently and it's hard to keep
track, but IIRC you're the guy with the badly-stuffed sys.path ...
have a look on your disk(s). OTOH maybe inspect depends on the
internal call stack implementation --- in that case you would need to
ask on the jython mailing-list.

HTH,
John
 
J

James Stroud

HMS said:
Is there a way that a function may access the doc string or func_name
of the caller?

Thanks,

jvh

Add a parameter to the function to avoid mutilating your code with
implementation specific inspection:

def fun(caller, *original_parameters):
do_something_to_caller_without_magic(caller)
do_something_with_original_parameters(*original_parameters)

James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top