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
zhuxiaoxi
V2EX  ›  Python

请问 from . import xxx 是什么用法,在何时使用?

  •  
  •   zhuxiaoxi ·
    zhuxiaoxi · 2018-07-22 21:45:20 +08:00 · 5421 次点击
    这是一个创建于 2077 天前的主题,其中的信息可能已经有所发展或是发生改变。
    4 条回复    2018-07-23 07:02:05 +08:00
    SimbaPeng
        1
    SimbaPeng  
       2018-07-22 22:18:02 +08:00 via Android   ❤️ 1
    py3 的相对导入,包内的模块导入处于同一顶级包下的模块、包、命名空间用的
    frostming
        2
    frostming  
       2018-07-22 22:18:34 +08:00
    (.) 相对引用啊

    假如当前 package 名是 foo,相当于
    from foo import xxxx
    wwqgtxx
        3
    wwqgtxx  
       2018-07-23 00:16:10 +08:00
    rogwan
        4
    rogwan  
       2018-07-23 07:02:05 +08:00 via Android
    相对路径优于绝对路径,否则换个地方就没法引用了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2875 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 14:25 · PVG 22:25 · LAX 07:25 · JFK 10:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.