3 ms·
I can't find it at the moment but wasn't there another solution to this problem where you could just populate an object at will (like matlab's struct for instan
by stinos 10y ago
I can't find it at the moment but wasn't there another solution to this problem where you could just populate an object at will (like matlab's struct for instance)? IIRC it was dict-based and allowed something like
foo = SomePythonWizardry()
foo.x = 1
foo.a.b = 2
print( foo ) #yields e.g. foo.x = 1, foo.a.b = 2
Or am I just dreaming? It would be all the goodness and none of the weird syntax.
- desdiv 10y agoYou're probably thinking of jsobject¹: from jsobject import Object foo = Object() foo.x = 1 foo.a = {} # foo.a.b will fail without this line foo.a.b = 2 print(foo) # prints: {'a': {'b': 2}, 'x': 1} ¹ https://pypi.python.org/pypi/jsobject/ https://pypi.python.org/pypi/jsobject/
- asciihacker 10y agoI think if you import mock you can create mock.Mock() instances that allow you to assign fields that way.