推荐学习书目
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 · Feb 4, 2016 via iPhone · 3320 views
    This topic created in 3776 days ago, the information mentioned may be changed or developed.
    Supplement 1  ·  Feb 4, 2016
    我想让在 manage.py 里 import 的代码都能访问 app.config
    https://github.com/LokiSharp/Sharloki-Blog
    5 replies    2016-02-04 22:19:59 +08:00
    fy
        1
    fy  
       Feb 4, 2016
    不懂, a 要调用 b ,但是 b 有个方法需要调用 a ,是这意思吗?
    braineo
        2
    braineo  
       Feb 4, 2016
    你是这个意思吗?
    ----------------------------------------------------------
    # a.py

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

    import b

    b.print_a(adict)

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

    def print_a(sth):
    print sth
    clino
        3
    clino  
       Feb 4, 2016
    在"b.py 中的函数"体内 import a 里的字典,不要再函数外 import
    LokiSharp
        4
    LokiSharp  
    OP
       Feb 4, 2016 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  
       Feb 4, 2016
    @LokiSharp 用我说的方法就可以啊
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   900 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 19:39 · PVG 03:39 · LAX 12:39 · JFK 15:39
    ♥ Do have faith in what you're doing.