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


Groups > comp.lang.python > #79800

Re: variable attribute name

References <6fc1feb3-651e-49e9-8a5d-66dc0599a754@googlegroups.com>
Date 2014-10-27 14:32 -0400
Subject Re: variable attribute name
From Larry Martell <larry.martell@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.15241.1414434766.18130.python-list@python.org> (permalink)

Show all headers | 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