【发布时间】:2017-12-22 03:59:49
【问题描述】:
我正在开发一个具有这么多功能的 python 模块。我想在某个特定位置的特定函数中插入几行。假设这是代码:
def abc():
#few lines of code
context = {}
return context
def xyz():
#few lines of code
context = {}
return context
现在我想在上下文之前添加“这是新行”,但仅在函数 xyz 中:
def abc():
#few lines of code
context = {}
return context
def xyz():
#few lines of code
This is new line
context = {}
return context
如何使用 sed 做到这一点?此外,必须添加新行的功能可以在任何地方,不必在开头或结尾。
【问题讨论】:
-
如果可以使用 Python,为什么还要“使用 sed”? 8-)
-
@Blotosmetek 实际上我正在创建一个可以应用于该 python 模块的任何版本的补丁