Modifying a variable in a module imported using from … import *

前端 未结 3 1359
野趣味
野趣味 2021-01-11 19:15

Consider the following code:

#main.py
From toolsmodule import *
database = \"foo\"

#toolsmodule
database = \"mydatabase\"

As it seems, thi

3条回答
  •  粉色の甜心
    2021-01-11 20:13

    Why don't you do it like that:

    import toolsmodule
    toolsmodule.database = "foo"
    from toolsmodule import *  #bad idea, but let's say you have to..
    print database #outputs foo
    

提交回复
热议问题