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


Groups > comp.lang.python > #79800

Re: variable attribute name

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <larry.martell@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'attribute': 0.07; 'string': 0.09; 'python': 0.11; 'denotes': 0.16; 'object()': 0.16; 'subject:variable': 0.16; 'variable.': 0.16; 'wrote:': 0.18; '(not': 0.18; 'variable': 0.18; 'to:name:python-list@python.org': 0.22; 'advise.': 0.24; 'mon,': 0.24; 'pass': 0.26; 'code:': 0.26; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'class': 0.32; 'but': 0.35; 'received:google.com': 0.35; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'name': 0.63; 'here': 0.66
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=nTYNJpuiITPZoRArEbC43VpdT5SlxQ9uVr+pQKJlUIM=; b=OMWhXKTy+KpPWi3myFbl3RLrUfNyyqxuTMJBQVeeu0MsTaH5SGFzmRjQc04ltAk1Hz bnoc+YyxoaKYk8cJwySdiDjfWQv129H2WKynM5UVYB0+oQvb1Vl/ga2jtC8flqgSwWiW BVEAGfw9C3G0GR/mGwsbbBa/FdHWynRfS5NIq39r5rns21QGW0XoKcFD6x67VZz0POut prWIU4mt0ZUVqYffhiOgttUO3UlbBIla3vL9xUf8111KNBYj7hj/2JGPPSwS8dfQwF0D WL2qrEzu5o8u1R4VnIEhe/bhoI9v3cwXrqnXL+qRbu2IS+jzZzMKT5VXGPdEDpHCHAkT d0gw==
MIME-Version 1.0
X-Received by 10.180.103.33 with SMTP id ft1mr22244630wib.71.1414434757564; Mon, 27 Oct 2014 11:32:37 -0700 (PDT)
In-Reply-To <6fc1feb3-651e-49e9-8a5d-66dc0599a754@googlegroups.com>
References <6fc1feb3-651e-49e9-8a5d-66dc0599a754@googlegroups.com>
Date Mon, 27 Oct 2014 14:32:37 -0400
Subject Re: variable attribute name
From Larry Martell <larry.martell@gmail.com>
To "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15241.1414434766.18130.python-list@python.org> (permalink)
Lines 11
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1414434766 news.xs4all.nl 2846 [2001:888:2000:d::a6]:46368
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:79800

Show key headers only | View raw


On Mon, Oct 27, 2014 at 2:23 PM, Harvey Greenberg <hjgreenberg@gmail.com> wrote:
> I want to let the name of an attribute be the string value of a variable.  Here is some code:
>
> class Object(object): pass
> A = Object()
> s = 'attr'
> A.<s> = 1
>
> The last line denotes the variable value by <s> (not a python form).  What I want is to have A.attr = 1, but 'attr' determined by the value of s.  Please advise.

setattr(A, s, 1)

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


Thread

variable attribute name Harvey Greenberg <hjgreenberg@gmail.com> - 2014-10-27 11:23 -0700
  Re: variable attribute name Larry Martell <larry.martell@gmail.com> - 2014-10-27 14:32 -0400
  Re: variable attribute name Ned Batchelder <ned@nedbatchelder.com> - 2014-10-27 15:48 -0400

csiph-web