<div><font class="Apple-style-span" face="'courier new', monospace"> print "Thanks. That chair is %s." % chair</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> if kw:</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> for key, val in kw.iteritems():</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> print "I wasn't expecting the (%s) %s!" % (val, key)</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">d = json.loads('{"chair":"comfy","inquisition":"Spanish"}')</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">expect_a_chair(**d)</font></div><div><font class="Apple-style-span" face="'courier new', monospace">try:</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> expect_a_chair({})</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">except TypeError:</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> print "No chair."</font></div>
<div><br></div><div>The ** operator does this. Notice that nowhere in that python code (not counting the json) do I have to put "chair" in quotes.</div><div><br></div><div>Honestly, this solves my current use case. I can use functions like expect_a_chair for everything I need right now.</div>
<div><br></div><div>But perhaps, if there were a quote-free way to access string-based dict items, it should be based on this. The problem is, this ** operator is a unary operator, and the non-unary ** is already taken. </div>
<div><br></div><div>So, I don't have a perfect name for my proposed quoteless synonym for '["..."]'. My best option is '*.'. Note that this could also be used for unpacking, and with defaults:</div>
<div>d*.(x,y,z) #=== (d["x"], d["y"], d['z'])</div><div>e=d*.(e=None) #like 'e=d.get("e", None)'. </div><div><br></div><div>Does this sound worth-it to anyone?</div><div><br>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4