Quick actions

cmd+k|ctrl+k

Navigation

Languages

Untitled

Snippet info

Language

Python

Visibility

unlisted

Author

legacy-anonymous

Created

2024-10-16T13:17:42.407914Z

Updated

2024-10-16T13:17:42.407914Z

import ast

s = """
# 1+1<3
print("1 + 1 < 3", 1+1<3)
print(1+1<<3)
"""
print("before")
print(s)

print("after")
tree = ast.parse(s)
print(ast.dump(tree, indent=4))
tree.body[0].value.args[1].ops[0] = ast.Gt()
print(ast.unparse(tree))

print("visit" *5)
tree = ast.parse(s)
class RewriteOp(ast.NodeTransformer):

    def visit_Lt(self, node):
        return ast.Gt()

node = RewriteOp().visit(tree)
print(ast.unparse(node))
INFO