syntax for dicts with arguments
Idea: how about an alternative syntax specifically for argument list definitions. To be able to write down a dict holding argument list in simpler form, namely with a function-like syntax: mystyle = dict ** (linestyle="dotted", marker="s", color= (0.1,0.1,0.0), markersize=4) as a synonym for the common dict:mystyle= {"linestyle": "dotted", marker": "s", "color": (0.1,0.1, 0.0), "markersize": "4"} (The example is from Mathplotlib plot line style.) Pros: same look as in functon arguments, thus less visual confusion and less re-typing, With such syntax I could simply copy-paste, say, examples from library docs to separate dict "mystyle" and ready to insert the dict into other function making use of dict unpackong. If need to move some argument from "mystyle" to function call, no re-typing needed. Also it looks significantly cleaner with less quotes and less colons. Mikhail
dict already takes **kwargs... is this what you want? mystyle = dict(linestyle="dotted", marker="s", color= (0.1,0.1,0.0), markersize=4) All I did was remove the “**”. Brandt
On Sep 26, 2019, at 13:24, Mikhail V <mikhailwas@gmail.com> wrote:
mystyle = dict ** (linestyle="dotted", marker="s", color= (0.1,0.1,0.0), markersize=4)
participants (2)
-
Brandt Bucher
-
Mikhail V