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

Python 模块导入问题

  •  
  •   yxy2829 · 2017-07-20 21:44:56 +08:00 · 1973 次点击
    这是一个创建于 2444 天前的主题,其中的信息可能已经有所发展或是发生改变。
    .
    ├── aaa
    │   ├── a.py
    │   └── __init__.py
    └── bbb
    ├── b.py
    └── __init__.py

    目录结构如上,如何在 b.py 中调用 a.py 的方法?
    python2.7
    4 条回复    2017-07-21 21:51:27 +08:00
    lazydao
        1
    lazydao  
       2017-07-20 22:51:08 +08:00 via iPhone
    from aaa import a
    yxy2829
        2
    yxy2829  
    OP
       2017-07-20 22:55:59 +08:00
    import sys
    sys.path.append('../')
    from aaa import a
    julyclyde
        4
    julyclyde  
       2017-07-21 21:51:27 +08:00
    没看明白。为什么要..上层目录?
    b 和 aaa 不是平级吗?应该可以 from aaa 啊
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2909 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 14:16 · PVG 22:16 · LAX 07:16 · JFK 10:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.