How do I get the filepath for a class in Python? How do I get the filepath for a class in Python? python python

How do I get the filepath for a class in Python?


You can use the inspect module, like this:

import inspectinspect.getfile(C.__class__)


try:

import sys, osos.path.abspath(sys.modules[LocationArtifact.__module__].__file__)


This is the wrong approach for Django and really forcing things.

The typical Django app pattern is:

  • /project
    • /appname
      • models.py
      • views.py
      • /templates
        • index.html
        • etc.