nice python solution

Uwe Schmitt uwe at rocksport.de
Sun Nov 18 17:24:52 EST 2001


Chris Liechti <cliechti at gmx.net> wrote:
| [posted and mailed]

| Uwe Schmitt <uwe at rocksport.de> wrote in news:9t95gu$ab7l1$1 at hades.rz.uni-
| sb.de:
|> Hi,
|> 
|> i there a nice python shortcut for:
|>     if idx=0:
|>        a=val
|>     elif idx=1:
|>        b=val
|> 
|> ???
|> I tried
|>    (a,b)[idx] = val
|> 
|> but this does not work, i get an error message.
|> 
|> Greetings, Uwe.


| if you have an object:
|   setattr(obj,('a','b')[idx], val)

| or a bit uglier
|   obj.__dict__[('a','b')[idx]] = val

in my case a and b are floats....

greetings and thanks, uwe.

-- 
Dr. rer. nat. Uwe Schmitt                       Uwe.Schmitt at num.uni-sb.de
Universitaet des Saarlandes                     Angewandte Mathematik
Building 36.1 Room 4.17         PO-Box 151150   D-66041 Saarbruecken
Mobile:0177/6806587    Fax:+49(0)681/302-4435   Office:+49(0)681/302-2468



More information about the Python-list mailing list