V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
yxy2829
V2EX  ›  Python

Python 模块导入问题

  •  
  •   yxy2829 · Jul 20, 2017 · 2674 views
    This topic created in 3208 days ago, the information mentioned may be changed or developed.
    .
    ├── aaa
    │   ├── a.py
    │   └── __init__.py
    └── bbb
    ├── b.py
    └── __init__.py

    目录结构如上,如何在 b.py 中调用 a.py 的方法?
    python2.7
    4 replies    2017-07-21 21:51:27 +08:00
    lazydao
        1
    lazydao  
       Jul 20, 2017 via iPhone
    from aaa import a
    yxy2829
        2
    yxy2829  
    OP
       Jul 20, 2017
    import sys
    sys.path.append('../')
    from aaa import a
    julyclyde
        4
    julyclyde  
       Jul 21, 2017
    没看明白。为什么要..上层目录?
    b 和 aaa 不是平级吗?应该可以 from aaa 啊
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2482 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 12:03 · PVG 20:03 · LAX 05:03 · JFK 08:03
    ♥ Do have faith in what you're doing.