Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the current file, current class, and current method with Python?

  • Name of the file from where code is running
  • Name of the class from where code is running
  • Name of the method (attribute of the class) where code is running
like image 610
Max Frai Avatar asked May 21 '09 17:05

Max Frai


1 Answers

Here is an example of each:

from inspect import stack  class Foo:     def __init__(self):         print __file__         print self.__class__.__name__         print stack()[0][3]  f = Foo() 
like image 51
Andrew Hare Avatar answered Sep 18 '22 02:09

Andrew Hare