1

I am using pyAMF and I do receive a TypedObject that is in fact a nested dictionary. I want to convert this to a python dictionary.

sorin
  • 161,544
  • 178
  • 535
  • 806

1 Answers1

1

You should be able to wrap it in dict(obj) or call obj.copy() to convert it:

>>> type(o)
<class 'pyamf.TypedObject'>
>>> type(o.copy())
<type 'dict'>
>>> o.copy()
{'abc': 123}
samplebias
  • 37,113
  • 6
  • 107
  • 103
  • I don't know exactly why, but what I tested initially `dict(obj)` doesn't work. Still, your second variant works! – sorin May 03 '11 at 16:41
  • @Sorin, glad it helped! Strange, since dict(obj) works for me, which makes sense since TypedObject inherits directly from dict. – samplebias May 03 '11 at 17:04
  • Probably it has something to do with the fact that I do have a nested dictionary. – sorin May 03 '11 at 18:29
  • Hmm, the dict(obj) worked for me, even for nested TypedObjects and dicts. – samplebias May 03 '11 at 18:30