推荐学习书目
› 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
bleutail
V2EX  ›  Python

如何永久修改其他模块中的变量

  •  
  •   bleutail · Sep 21, 2021 · 1859 views
    This topic created in 1841 days ago, the information mentioned may be changed or developed.

    先祝各位中秋愉快~

    例如在模块 modulea 中设置 A = True 然后在模块 moduleb 中

    from modulea import *
    print(A)
    
    def fuc():
    	global A
    	A = False
    print(A)
    

    发现输出是两个真值

    问题一:如果我想在模块 b 中修改 A 怎么做呢? 问题二:假如有三个模块 abc,模块 a 用于存放对象 x,模块 b 每天修改对象 x,模块 c 每天调用修改后的 x 应该如何实现?如果只能在 b 中创建一个变量等于 A 再修改的话那么模块多了以后不好管理,我感觉用模块意义也不大了

    billlee
        1
    billlee  
       Sep 21, 2021
    1. 别用 import *
    2. 你没有调用 fuc() 函数

    先搞清楚基础语法吧。。
    bleutail
        2
    bleutail  
    OP
       Sep 22, 2021
    @billlee 谢谢,是我脑瘫了...
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   819 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 22:30 · PVG 06:30 · LAX 15:30 · JFK 18:30
    ♥ Do have faith in what you're doing.