V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
halicando
V2EX  ›  Python

实际应用 django 时发现,有的版本,在 同一个 app 下,views 中无需 import 就能直接使用 model 类。官方文档里有这一说?

  •  
  •   halicando · 2013-06-26 10:42:23 +08:00 · 3124 次点击
    这是一个创建于 3956 天前的主题,其中的信息可能已经有所发展或是发生改变。
    7 条回复    1970-01-01 08:00:00 +08:00
    mutoulbj
        1
    mutoulbj  
       2013-06-26 10:44:15 +08:00
    有吗?
    qdvictory
        2
    qdvictory  
       2013-06-26 10:45:51 +08:00
    有可能是间接引用了吧
    halicando
        3
    halicando  
    OP
       2013-06-26 10:48:20 +08:00
    @qdvictory 比如呢?
    walnutist
        4
    walnutist  
       2013-07-09 14:51:26 +08:00
    x.py

    from some.package import TheBadAssClass

    y.py

    from x import *

    print dir(TheBadAssClass)

    除非在x.__all__中显示定义不暴露TheBadAssClass出来,否则从x中import *,会把TheBadAssClass带进来的
    qdcanyun
        5
    qdcanyun  
       2013-07-09 16:20:48 +08:00
    能否举个例子。。。。
    如果4楼说的情况 感觉尽量别这么用 还是独立的写一条from...import...吧 不然就会产生依赖关系 以后如果有了bug可能会有什么影响。。。。
    buru
        6
    buru  
       2013-07-09 16:55:09 +08:00
    4楼正解
    个人感觉独立写一条import比较好
    siteshen
        7
    siteshen  
       2013-07-11 01:08:30 +08:00
    和 django 没啥关系。

    from X import * imports the module X, and creates references in the current namespace to all public objects defined by that module (that is, everything that doesn’t have a name starting with “_”).
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3340 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 12:15 · PVG 20:15 · LAX 05:15 · JFK 08:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.