Created
April 20, 2013 04:31
-
-
Save hirokiky/5424755 to your computer and use it in GitHub Desktop.
Supplying deep copied attributes from a module. Following python code expect to be placed like app/consts/__init__.py.
Then you can place app/consts/constant_values.py having constant values, and get deep copied values.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import copy | |
class AttributeSupplier(object): | |
def __init__(self, *args): | |
self.consts_module = __import__(*args) | |
def __getattr__(self, name): | |
return copy.deepcopy(getattr(self.consts_module, name)) | |
consts = AttributeSupplier('constant_values', globals(), locals(), ['app', 'consts']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment