Given a class C in Python, how can I determine which file the class was defined in? I need something that can work from either the class C, or from an instance off C.
<You can use the inspect module, like this:
import inspect
inspect.getfile(C.__class__)
This is the wrong approach for Django and really forcing things.
The typical Django app pattern is:
try:
import sys, os
os.path.abspath(sys.modules[LocationArtifact.__module__].__file__)