Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #15596

Re: Get keys from a dicionary

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 <d@davea.name>
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 <d@davea.name>
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 <moura.mario@gmail.com>
Subject Re: Get keys from a dicionary
References <8f5215a8-d08f-4355-a5a2-77fcaa32c92d@j10g2000vbe.googlegroups.com> <1e00ab59-8fc5-4bd7-b52c-f98f3b0b4473@x8g2000yql.googlegroups.com> <aac0b123-673b-4d8f-bc05-1f639515a951@c18g2000yqj.googlegroups.com>
In-Reply-To <aac0b123-673b-4d8f-bc05-1f639515a951@c18g2000yqj.googlegroups.com>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2647.1321030075.27778.python-list@python.org> (permalink)
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

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Get keys from a dicionary macm <moura.mario@gmail.com> - 2011-11-11 05:31 -0800
  Re: Get keys from a dicionary Jon Clements <joncle@googlemail.com> - 2011-11-11 08:09 -0800
    Re: Get keys from a dicionary macm <moura.mario@gmail.com> - 2011-11-11 08:33 -0800
      Re: Get keys from a dicionary macm <moura.mario@gmail.com> - 2011-11-11 08:38 -0800
      Re: Get keys from a dicionary Dave Angel <d@davea.name> - 2011-11-11 11:47 -0500
      Re: Get keys from a dicionary John Gordon <gordon@panix.com> - 2011-11-11 17:28 +0000
  Re: Get keys from a dicionary John Gordon <gordon@panix.com> - 2011-11-11 16:25 +0000
    Re: Get keys from a dicionary macm <moura.mario@gmail.com> - 2011-11-11 08:36 -0800
  Re: Get keys from a dicionary Gelonida N <gelonida@gmail.com> - 2011-11-11 18:29 +0100
  Re: Get keys from a dicionary Gelonida N <gelonida@gmail.com> - 2011-11-11 18:45 +0100
    Re: Get keys from a dicionary John Gordon <gordon@panix.com> - 2011-11-11 17:51 +0000
  Re: Get keys from a dicionary alex23 <wuwei23@gmail.com> - 2011-11-13 21:42 -0800
  Re: Get keys from a dicionary alex23 <wuwei23@gmail.com> - 2011-11-13 21:44 -0800
  Multilevel dicts/arrays v. tuples as keys? [Was: Re: Get keys from a dicionary] Matej Cepl <mcepl@redhat.com> - 2011-11-14 11:05 +0100
    Re: Multilevel dicts/arrays v. tuples as keys? [Was: Re: Get keys from a dicionary] Tim Golden <mail@timgolden.me.uk> - 2011-11-14 10:42 +0000
    Re: Multilevel dicts/arrays v. tuples as keys? Peter Otten <__peter__@web.de> - 2011-11-14 11:47 +0100
      Re: Multilevel dicts/arrays v. tuples as keys? alex23 <wuwei23@gmail.com> - 2011-11-14 19:07 -0800

csiph-web