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

Python 怎么能让在 a.py 里 import 的 b.py 中的函数调用 a.py 中的字典?

  •  
  •   LokiSharp ·
    LokiSharp · 2016-02-04 15:08:30 +08:00 via iPhone · 2815 次点击
    这是一个创建于 3017 天前的主题,其中的信息可能已经有所发展或是发生改变。
    第 1 条附言  ·  2016-02-04 16:16:05 +08:00
    我想让在 manage.py 里 import 的代码都能访问 app.config
    https://github.com/LokiSharp/Sharloki-Blog
    5 条回复    2016-02-04 22:19:59 +08:00
    fy
        1
    fy  
       2016-02-04 16:39:31 +08:00
    不懂, a 要调用 b ,但是 b 有个方法需要调用 a ,是这意思吗?
    braineo
        2
    braineo  
       2016-02-04 16:41:26 +08:00
    你是这个意思吗?
    ----------------------------------------------------------
    # a.py

    adict = {'what':'the', 'hell':'?'}

    import b

    b.print_a(adict)

    ------------------------------------------------------------
    #b.py

    def print_a(sth):
    print sth
    clino
        3
    clino  
       2016-02-04 16:41:32 +08:00
    在"b.py 中的函数"体内 import a 里的字典,不要再函数外 import
    LokiSharp
        4
    LokiSharp  
    OP
       2016-02-04 20:50:53 +08:00 via iPhone
    @fy
    @braineo
    @clino
    https://github.com/LokiSharp/Sharloki-Blog
    我想在 /manager.py 里 import 的 /app/email.py 这里调用 /manager.py 里定义的 app.config, 并且在 /app/main/view.py 里调用传入了 app.config 中参数的 send_email()
    clino
        5
    clino  
       2016-02-04 22:19:59 +08:00
    @LokiSharp 用我说的方法就可以啊
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4552 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 10:10 · PVG 18:10 · LAX 03:10 · JFK 06:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.