Importing global namespace in python

后端 未结 1 1350
长情又很酷
长情又很酷 2021-01-20 00:38

let\'s say i have the following files:

a.py

glo_var = 0
def func():
    global glo_var
    glo_var = 5
    print \"A %d\" % (glo_var)
相关标签:
1条回答
  • 2021-01-20 01:14

    Using from ... import ... copies the references from the other module. Rebinding the value in the original causes it to have a new reference, breaking the link between a.glo_var and b.glo_var permanently. Either use a mutable object and mutate it, or reimport a.glo_var whenever you need the updated value.

    0 讨论(0)
提交回复
热议问题