Closed Skylion007 closed 3 years ago
$ astpretty --no-show-offsets /dev/stdin <<< `cat example.txt`
Module(
body=[
Expr(
value=Compare(
left=Name(id='key', ctx=Load()),
ops=[In()],
comparators=[
Call(
func=Attribute(
value=Name(id='dict', ctx=Load()),
attr='keys',
ctx=Load(),
),
args=[],
keywords=[],
),
],
),
),
],
type_ignores=[],
)
Explanation
Most of the discussion of the motivation about this rule can be found in this very detailed StackOverflow post
Example
Basically, the later way of doing this pythonic and slightly more performant and arguably more Readable. The previous method only exists for legacy code (<= python 2.2). So there is no reason to use the former in modern codebases.