简体   繁体   English

如何传递实例变量作为参数,该参数可以在函数中多次调用?

[英]How to pass instance variable as argument which can persist in function for multiple calls?

I'm using Androguard to analyze some malware files. 我正在使用Androguard分析一些恶意软件文件。 Currently I'm trying to get androsim.py to analyze a file with its entire directory. 目前,我正在尝试获取androsim.py来分析具有整个目录的文件。 The objective is to iterate over all folders where in each folder you compare files with the other files in your folder. 目的是遍历所有文件夹,在每个文件夹中,您将文件与文件夹中的其他文件进行比较。

I'm not able to get androsim running in another script, one of the arguments to the main function is an instance variable, whose value is transient and the code breaks? 我无法在另一个脚本中运行androsim,主函数的参数之一是实例变量,其值是瞬态的并且代码中断了?

import androsim
import sys, os

from optparse import OptionParser  
from androsim import options 
parser = OptionParser() 
for option in options :
   param = option['name']
   del option['name']
   parser.add_option(*param, **option)

options, arguments = parser.parse_args()
sys.argv[:] = arguments
print options,arguments

androsim.main(options, arguments)

It's not entirely clear what you're after here, but if the instance object you have is mutating between passing it into the function and using it, then make a copy of it and pass the copy in instead: 目前尚不清楚您要执行的操作,但是如果您拥有的实例对象在将其传递给函数和使用它之间发生了变异,请对其进行复制并传递给副本:

from copy import deepcopy
intransient = deepcopy(options)

androsim.main(intransient, arguments)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将实例绑定描述符作为参考参数传递给 function? - How can I pass an instance binding descriptor as a reference argument to a function? 我如何在python中的函数参数中传递实例属性 - How can i pass instance attribute in function argument in python 如何在 Python 参数中传递 Ruby 实例变量 - How to pass Ruby instance variable in a Python argument 如何创建一个 function 调用另一个 function 并将实例属性作为参数传递? - How can I create a function that calls another function and passes in an instance attribute as an argument? 将实例作为函数参数传递 - Pass instance as function argument 如果变量存在,如何将变量作为参数传递给 function - How to pass a variable as an argument to a function if the variable exists 为类的实例变量传递参数 - pass argument for instance variable for class 如何将使用实例变量的实例方法作为另一个函数的参数传递? - How to pass an instance method, that uses instance variables, as argument to another function? 如何将参数名称传递给函数的变量名称 - How to pass a name of an argument to the variable names of a function 如何在 python 中将变量作为另一个 function 的参数传递 - How to pass a variable as an argument of another function in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM