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


Groups > comp.lang.python > #56919 > unrolled thread

Re: how to add object from dict

Started byChris Angelico <rosuav@gmail.com>
First post2013-10-17 11:46 +1100
Last post2013-10-17 09:02 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: how to add object from dict Chris Angelico <rosuav@gmail.com> - 2013-10-17 11:46 +1100
    Re: how to add object from dict Steven D'Aprano <steve@pearwood.info> - 2013-10-17 09:02 +0000

#56919 — Re: how to add object from dict

FromChris Angelico <rosuav@gmail.com>
Date2013-10-17 11:46 +1100
SubjectRe: how to add object from dict
Message-ID<mailman.1134.1381970815.18130.python-list@python.org>
On Thu, Oct 17, 2013 at 11:43 AM, MRAB <python@mrabarnett.plus.com> wrote:
> I'm guessing, but perhaps you need:
>
>     instance = getattr(self, "%s" % key)

How's that different from getattr(self,str(key))?

ChrisA

[toc] | [next] | [standalone]


#56947

FromSteven D'Aprano <steve@pearwood.info>
Date2013-10-17 09:02 +0000
Message-ID<525fa7b1$0$30000$c3e8da3$5496439d@news.astraweb.com>
In reply to#56919
On Thu, 17 Oct 2013 11:46:52 +1100, Chris Angelico wrote:

> On Thu, Oct 17, 2013 at 11:43 AM, MRAB <python@mrabarnett.plus.com>
> wrote:
>> I'm guessing, but perhaps you need:
>>
>>     instance = getattr(self, "%s" % key)
> 
> How's that different from getattr(self,str(key))?

Are you blind man? The first one has a % symbol and the second one has 
two extra brackets.



*wink*

-- 
Steven

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web