用这段python黑色魔法修改您自己的源代码
replace_me的Python项目详细描述
用这段python黑色魔法修改您自己的源代码。
当一段代码调用replace_me(value)时,该行将是 替换为给定的value。如果要插入注释并 保留插入的行,使用insert_comment(value)。
attention:调用这些函数将修改源代码。 保留备份。
示例:
from replace_me import replace_me, insert_comment # If you run this program, this source code will change. # These two lines will become the same: # Hello World replace_me("Hello World", as_comment=True) # Code generation. Creates a hard coded list of 100 numbers. replace_me('numbers = ' + str(list(range(100)))) import random # The next comment will be replaced with a random number. insert_comment(random.randint(1, 10)) # ?? # Pseudo-quine, replaces the line with itself. quine = 'replace_me(quine)' replace_me(quine)