[Tutor] How can a function know where it was called from
Ewald Ertl
ewald.ertl at hartter.com
Thu Mar 2 12:58:59 CET 2006
Hi Ben!
After looking at the modules I detected the traceback-Module in my installation:
>>> import traceback
>>> def two():
... one()
...
>>> two()
>>> def one():
... print traceback.extract_stack()
...
>>> def two():
... one()
...
>>> two()
[('<stdin>', 1, '?', None), ('<stdin>', 2, 'two', None), ('<stdin>', 2, 'one', None)]
maybe this could be a start for your investigation
HTH Ewald
Ben Vinger wrote:
> Hello
>
> I want myfunction in the pseudocode below return something different if
> it was called from indexfunction.
>
> def indexfunction():
> blah
>
> def myfunction():
> x = 'whatever'
> if <myfunction was called from indexfunction>:
> return x
> else:
> return <header> + x + <footer>
>
>
> Thanks
> Ben
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
--
Ing. Ewald Ertl HartterGruppe Phone : +43-3352-33085-558
trinomic Projektmanagement & Informationstechnik GmbH Fax : +43-3352-33085-600
Wiener Straße 41 mailto:ewald.ertl at trinomic.com
A-7400 Oberwart http://www.trinomic.com mailto:ewald.ertl at hartter.com
More information about the Tutor
mailing list