在类的控制台中打印结果

2024-04-25 20:37:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我对OOPython还很陌生,我尝试简单地执行parse_param_paths()的值来获得dictpath的值

我有:

class Injection:
    def __init__(self):
        self.tld_object = None
        self.path_object = None 
        print "Class Initialized"

    def gather_path(self):
        self.path_object = PathsOfDomain.objects.filter(FKtoTld=3)
        return self.path_object

    def parse_param_paths(self):
        if self.path_object is not None:
            dictpath = {}
            for path in self.path_object:
                self.params = path.split("?")[1].split("&")
                out = list(map(lambda v: v.split("=")[0] +"=" + self.fuzz_vectors, self.params))
                dictpath[path] = out
            print dictpath

在此非常感谢您的帮助。谢谢


Tags: pathselfnoneobjectparamparsedefparams
1条回答
网友
1楼 · 发布于 2024-04-25 20:37:25
from myapp import Injection

inj = Injection() # create an instance 

inj.gather_path() # to set self.object to a value other than None

inj.parse_param_paths() # call method with instance

print self.path_object is not None放在if self.path_object is not None前面

如果self.path_objectNone,您将不会得到任何输出,因为条件不会计算为True,因此您将不会再执行方法中的行。你知道吗

相关问题 更多 >