I have a project that is organized something like
project/
__init__.py
builder.py
component/
__init__.py
Within builder.py
, I have a class called Builder that has several class attributes in order to implement the Borg pattern. The trouble arises when I try to import Builder in component/__init__.py
and make changes to class attributes. It seems that whatever changes I make to the class attributes in the package are undone when the function returns.
UPDATE: Here is a simple example of what is happening.
builder.py
class Builder(object):
attribute = True
import component
print Builder.attribute
component/__init__.py
from project.builder import Builder
Builder.attribute = False
Output:
False
True
Judging by the fact that two lines are printed, I would guess that the code in builder.py
is being executed twice, which resets the value of attribute
to True.