推荐学习书目
› 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 · Jun 26, 2013 · 4183 views
    This topic created in 4840 days ago, the information mentioned may be changed or developed.
    7 replies  •  1970-01-01 08:00:00 +08:00
    mutoulbj
        1
    mutoulbj  
       Jun 26, 2013
    有吗?
    qdvictory
        2
    qdvictory  
       Jun 26, 2013
    有可能是间接引用了吧
    halicando
        3
    halicando  
    OP
       Jun 26, 2013
    @qdvictory 比如呢?
    walnutist
        4
    walnutist  
       Jul 9, 2013
    x.py

    from some.package import TheBadAssClass

    y.py

    from x import *

    print dir(TheBadAssClass)

    除非在x.__all__中显示定义不暴露TheBadAssClass出来,否则从x中import *,会把TheBadAssClass带进来的
    qdcanyun
        5
    qdcanyun  
       Jul 9, 2013
    能否举个例子。。。。
    如果4楼说的情况 感觉尽量别这么用 还是独立的写一条from...import...吧 不然就会产生依赖关系 以后如果有了bug可能会有什么影响。。。。
    buru
        6
    buru  
    PRO
       Jul 9, 2013
    4楼正解
    个人感觉独立写一条import比较好
    siteshen
        7
    siteshen  
       Jul 11, 2013
    和 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 “_”).
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2599 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 09:11 · PVG 17:11 · LAX 02:11 · JFK 05:11
    ♥ Do have faith in what you're doing.