Aristide
Aristide

Reputation: 3994

Using relative import without from

Instead of:

from .model import Foo, Bar

I would like to:

import .model

This raises a syntax error. Is there a way to do it?

Upvotes: 7

Views: 470

Answers (1)

Olivier Melançon
Olivier Melançon

Reputation: 22314

Anything following an import keyword must be a valid Python name as it will be added to your scope under that same name.

Instead, do the following.

from . import model

Upvotes: 7

Related Questions