Last active
July 24, 2016 11:12
-
-
Save macrat/584fb53a067ab23d75f16e8949a863c8 to your computer and use it in GitHub Desktop.
あらゆる文字列が"hello!"で置き換えられるpython処理系的なもの。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ast | |
import sys | |
if len(sys.argv) != 2: | |
print('usage: python {} [FILE.py]'.format(sys.argv[0])) | |
sys.exit(1) | |
with open(sys.argv[1]) as f: | |
a = ast.parse(f.read(), f.name) | |
for x in ast.walk(a): | |
if isinstance(x, ast.Str): | |
x.s = 'hello!' | |
eval(compile(a, f.name, 'exec')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment