On 11/11/2011 11:33 AM, macm wrote:
Hi

Sorry ! My mistake.

myDict = {}
myDict['foo'] = {}
myDict['foo']['bar'] = 'works'
-----

def myFunction( MyObj ):
...     # MyObj is a nested dicionary (normaly 2 steps like myDict['foo']
['bar'])

No, it's not. It's a string "works". There's no dictionary passed to myFunction(), so it cannot do what you ask, slow or fast.

There are games you can play with introspection, but they are neither portable nor reliable.

...     # I want inspect this MyObj
...     # what keys was pass
...     print MyObj.keys() ## WRONG
...     # So What I want is :
...     # return foo bar

----------------

result = myFunction( myDict['foo']['bar'] )
result
Should print :

... foo bar

Best Regards

macm
Can you tell us the exact assignment, to see whether this is supposed to be a practical question, or a way to try to learn more about Python internals.



--

DaveA

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to