pistacchio pistacchio - 6 months ago 41
Python Question

Pylint: Relative import should be

I'm checking a module with Pylint. The project has this structure:


Within product I import entity like this:

from entity import Entity

but Pylint laments that:

************* Module builder.product
W: 5,0: Relative import 'entity', should be 'builder.entity'

from builder.entity import Entity
doesn't recognize the package, and
from ..builder.entity import Entity
doesn't work either. What is Pylint complaining about? Thanks

Answer Source

Python 2.5 introduces relative imports. They allow you to do

from .entity import Entity
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download