the annoying, verbose self

greg greg at cosc.canterbury.ac.nz
Sat Nov 24 18:29:33 EST 2007


Patrick Mullen wrote:
> Sometimes I actually use a dictionary, but typing all of the quotes
> for the keys gets old.

If the keys are all identifiers, you can use keyword
args to the dict constructor. So you could write

   self.__dict__.update(dict(var1 = 5,
     var2 = "a value", var3 = stuff))

if you really wanted to. (Don't be surprised if
everyone else refuses to maintain your code, though!)

--
Greg



More information about the Python-list mailing list