Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Consider the following code:

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

#toolsmodule
database = "mydatabase"

As it seems, this creates one variable in each module with different content. How can I modify the variable inside toolsmodule from main? The following does not work:

toolsmodule.database = "foo"
like image 868
David Avatar asked Jan 21 '11 12:01

David


1 Answers

Sounds like yet another of the multitude of good reasons not to use from toolsmodule import *.

If you just do import toolsmodule, then you can do toolsmodule.database = 'foo', and everything is wonderful.

like image 67
Daniel Roseman Avatar answered Oct 12 '22 15:10

Daniel Roseman