Proper relative imports: “Unable to import module”

前端 未结 4 1814
南方客
南方客 2021-02-12 11:34

I have a project structured like this:

.
└── myapp
    ├── app.py
    ├── models
    │   ├── hello.py
    │   └── world.py
    └── requirements.txt
4条回答
  •  长情又很酷
    2021-02-12 12:19

    Since hello.py and world.py are in the same folder (aka package), you should import the Hello class in world.py as follow:

    from .hello import Hello
    

    As described in this thread: What does a . in an import statement in Python mean?

    The . is here to indicate the import from the current package.

提交回复
热议问题