Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.030 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'python': 0.08; '>>>>': 0.09; 'foo': 0.09; 'subject:keys': 0.09; 'am,': 0.12; 'def': 0.14; 'cc:addr:python-list': 0.15; 'mistake.': 0.16; 'received:192.168.1.104': 0.16; 'wrote:': 0.18; 'cc:no real name:2**0': 0.21; '-----': 0.23; 'dictionary': 0.23; 'header:In- Reply-To:1': 0.23; 'string': 0.23; 'cc:2**0': 0.25; 'not.': 0.27; 'pass': 0.28; 'cc:addr:python.org': 0.29; 'print': 0.29; 'there': 0.33; 'header:User-Agent:1': 0.33; 'keys': 0.34; 'nested': 0.34; 'supposed': 0.35; '...': 0.36; 'passed': 0.37; 'but': 0.37; 'question,': 0.38; 'received:192': 0.38; 'should': 0.39; "there's": 0.39; "it's": 0.39; 'subject:: ': 0.39; 'more': 0.60; 'exact': 0.68; 'header:Reply-To:1': 0.70; 'subject:Get': 0.71; 'reply-to:no real name:2**0': 0.71; '11:33': 0.84; 'ask,': 0.91 Date: Fri, 11 Nov 2011 11:47:21 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Thunderbird/3.1.15 MIME-Version: 1.0 To: macm Subject: Re: Get keys from a dicionary References: <8f5215a8-d08f-4355-a5a2-77fcaa32c92d@j10g2000vbe.googlegroups.com> <1e00ab59-8fc5-4bd7-b52c-f98f3b0b4473@x8g2000yql.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:v0u9TwPRDM6dRprO6H1CopjCSL9I52tP3N0wCzrZLwR 3c5LWwVTIW1yO8xGomMgT52ZPDgH3hFSAf5hkoly5qg6sfijmy mW5y3uDctDFNAbuFA35hF2XL5SDNbqUvzHZJXS//qah7VGJa1M vQHk7olAfwldqqSU/fo1H1zhJOd3M5r0cSqO3m0Q25JBVOuR1H X7HylaOy9S/Pj2AM2KWsbB+IojWKm9JNt6+EI69NJn8fNeSlCn N7DJp9iVLJ8WmS4n5+3pHt1Wq3nC1QykKio06bbxbCHjnWgsED BHQq4GF7hE4HX2j5mQgDf+NqOch/SI4nGPVC/Bbktig8eB6kw= = Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: d@davea.name List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1321030075 news.xs4all.nl 6852 [2001:888:2000:d::a6]:39314 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:15596 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