Return to Snippet

Revision: 5862
at April 8, 2008 23:08 by kangell


Updated Code
class dictclass:
	"""Takes a dictionary and uses it as its __dict__ member, effectively
	making the dictionary supply the object's attributes."""
	
	def __init__( self, d ):
		self.__dict__ = d

Revision: 5861
at April 8, 2008 23:06 by kangell


Initial Code
class dictclass:
	"""Takes a dictionary and uses it as its __dict__ member, effectively
	making the dictionary supply the object's attributes."""
	
	def __init__( self, d ):
		self.__dict__ = d

Initial URL


Initial Description
This bit of code allows you to turn code that looks like this:

x = {'foo':1, 'bar':2 }
x['foo'] = 3

Into this:
x = dictclass( {'foo':1, 'bar':2 } )
x.foo = 3

Initial Title
Dictionary Class

Initial Tags
class

Initial Language
Python