【发布时间】:2015-07-15 01:35:36
【问题描述】:
我想使用 sed 命令注释掉以下代码行。
实际代码:
response = HttpResponse()
response['Content-Disposition'] = 'attachment; filename=%s.zip' % file_name.replace('.shp','')
response['Content-length'] = str(len(zip_stream))
response['Content-Type'] = mimetype
response.write(zip_stream)
return response
我想要什么:
#response = HttpResponse()
#response['Content-Disposition'] = 'attachment; filename=%s.zip' % file_name.replace('.shp','')
#response['Content-length'] = str(len(zip_stream))
#response['Content-Type'] = mimetype
#response.write(zip_stream)
#return response
唯一的问题是文件很大,到处都包含response,所以搜索应该根据上面提供的更具体。
给定的代码块位于特定文件的整个源代码的中间。
【问题讨论】:
-
所以你想注释掉任何包含变量名
response的行?你的问题不是很清楚。 -
抱歉混淆了.. 不,我只是想注释掉提供的特定块,因为代码在各个地方都包含响应,我们可以使用响应来匹配它。从整个源代码中,我只想注释掉上面提到的块..
-
那为什么不手动注释掉呢?否则 sed 没有模式(可以说)。
-
所以你的问题不是批量替换什么的。它更像是如何找到你想要的块。而不是搜索“响应”,您是否尝试过搜索整行代码?例如"response['Content-Disposition'] = 'attachment; filename=%s.zip' % file_name.replace('.shp','')"?
-
我正在开发
Shell Script,它将是一个自动安装程序,用于安装一个相当复杂的开源项目。目前对于想要尝试的用户来说,没有任何简单的选择。