模块没有子模块 [英] module has no submodule

查看:121
本文介绍了模块没有子模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个烧瓶网络应用程序,我有一些我不明白的东西。

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

我的 app 模块文件夹结构如下:

My app module folder structure goes like this :

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

在我的 init .py中:

from flask import Flask

app = Flask(__name__)
from app import views

现在如果我从IDLE导入app模块:

now if I import app module from IDLE:

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

模块 app 没有 toolxls 子模块。如何将toolxls.py添加到 app

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

推荐答案

在Python中,导入包时,子模块导入。如果要访问其命名空间,则必须显式导入它们。

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

这篇关于模块没有子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆