Skip to content

Instantly share code, notes, and snippets.

@hirokiky
Created April 20, 2013 04:31
Show Gist options
  • Save hirokiky/5424755 to your computer and use it in GitHub Desktop.
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.
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