0

I'd like to know if it is possible, and how to get the module name and class name where an object is instantiated.

For example:

class cool_ice:
  "code to get instantiating metadata"
  pass

class A:
  obj = cool_ice()

It would be nice to know that when cool_ice is instantiated in any class, there is some metadata about which class and which module the instantiation happened at.

So desired output could be like: Instantiation happened in class A, and under module xyz

dataviews
  • 2,466
  • 7
  • 31
  • 64
  • This is not possible as already answered here: https://stackoverflow.com/questions/1593632/python-get-name-of-instantiating-class – Ovski Sep 29 '22 at 18:10
  • what is the purpose of having an object instatiated inside another class? I think dependency injection is always better. – Lucas M. Uriarte Sep 29 '22 at 20:40

0 Answers0