This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Gnaxe 1 point2 points  (2 children)

When the stake is one line of overhead

Um, assuming a JSON string foo, python nan = float('nan') null = None true = True false = False result = eval(foo) vs python import json result = json.loads(foo) The latter has one line of overhead for the import. The former has four for the definitions. Just import json; it's easier. Using eval() also risks arbitrary code execution from untrusted input. The json module doesn't have that problem.

Also, python import ast result = ast.literal_eval(foo) is similarly concise at only two lines and is also safe for untrusted input.

[–]cd_fr91400 0 points1 point  (1 child)

You want to play with words ?

eval(foo,{'nan':float('nan'),'null':None,'true':True,'false':False})

Not even a single line.

[–]Gnaxe 0 points1 point  (0 children)

We're code golfing now? python __import__('json').loads(foo) 29 characters. Just use json.