Python class method throws AttributeError
The issue was twofold:
- The
User.py
file was in themodels/
folder, meaning that my import was actually looking for theUser
class in themodels.py
file, which no longer existed but still was being imported without error because themodels.pyc
file was still around - The import was incorrect for importing within a directory. it should have been
from models.User import User
, so long as themodels/
folder is a module, so all I needed to do then wastouch models/__init__.py
.
>>> class foo(object):... def __init__(self):... pass... @classmethod... def classmethod(cls):... return 0...>>> a = foo()>>> a.classmethod()0>>>