Can global variable be passed into Python function?
Marko Rauhamaa
marko at pacujo.net
Fri Feb 28 16:03:25 EST 2014
"Mark H. Harris" <harrismh777 at gmail.com>:
> Yep, my point exactly. nice illustration.
So now, for you and me: let's compare.
if key is ast.Assign:
return ' '.join(dump(t) for t in node.targets)
elif key is ast.AugAssign:
# Same target and same operator.
return dump(node.target) + dump(node.op) + "="
elif key is ast.Return:
# A return statement is always compatible with another.
return "(easy)"
elif key is ast.Expr:
# Calling these never compatible is wrong. Calling them
# always compatible will give lots of false positives.
return "(maybe)"
else:
# These ones are never compatible, so return some
# object that's never equal to anything.
return float("nan")
vs (my proposal):
with key from ast:
if Assign:
return ' '.join(dump(t) for t in node.targets)
elif AugAssign:
# Same target and same operator.
return dump(node.target) + dump(node.op) + "="
elif Return:
# A return statement is always compatible with another.
return "(easy)"
elif Expr:
# Calling these never compatible is wrong. Calling them
# always compatible will give lots of false positives.
return "(maybe)"
else:
# These ones are never compatible, so return some
# object that's never equal to anything.
return float("nan")
Which do *you* find more readable?
Marko
More information about the Python-list
mailing list