module has no submodule

2019-01-29 11:11发布

I am making a flask web app and I have something I don't understand.

My app module folder structure goes like this :

app\
  | static\
  | templates\
  | tmp\
  | __init__.py
  | run.py <= debug script
  | toolxls.py <= helper functions 
  | views.py

in my init.py :

from flask import Flask

app = Flask(__name__)
from app import views

now if I import app module from IDLE:

>>> import app
>>> dir(app)
['Flask', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'app', 'views']

module app has no toolxls sub-module. How can I add toolxls.py into app?

1条回答
贪生不怕死
2楼-- · 2019-01-29 11:21

In Python, submodules are not imported when you import the package. You must import them explicitly if you want access to their namespace.

import app.toolxls
查看更多
登录 后发表回答