Python 编写此辅助函数的更简单方法?
我有一个程序将在给定主机上启动nmap扫描,并添加我的参数:Python 编写此辅助函数的更简单方法?,python,python-2.7,Python,Python 2.7,我有一个程序将在给定主机上启动nmap扫描,并添加我的参数: def _get_all_info(self): """ get all the information from the scan """ def __add_options(): option_list = [] if self.opts is not None: for opt in self.opts: i
def _get_all_info(self):
"""
get all the information from the scan
"""
def __add_options():
option_list = []
if self.opts is not None:
for opt in self.opts:
if opt not in lib.attacks.nmap_scan.nmap_opts:
logger.warning(set_color(
"option '{}' is not a valid nmap option "
"skipping...".format(opt)
))
else:
option_list.append(opt)
return " ".join(options_list)
scanned_data = self.NM.scan(self.ip, ports=self.ports, arguments=__add_options())
if self.pretty:
scanned_data = json.dumps(scanned_data, indent=4, sort_keys=True)
return scanned_data
有没有更简单的方法来编写“添加选项”部分?使用并删除无用的日志记录:
def __add_options():
return " ".join([opt for opt in self.opts if opt in lib.attacks.nmap_scan.nmap_opts])
您可以删除
def
行并直接使用选项列表
。