Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
215 views
in Technique[技术] by (71.8m points)

python - Given a function, how can I get the arguments passed to it?

Here's what I am trying to do. I have a Prop class defined as this:

class Prop:
    def __init__(self, val, name=None):
        self.val=val
        self.name=name
    def getVal(self):
        return self.val
    def giveName(self, newname):
        self.name=newname
    def getName(self, name):
        return self.name
    def changeVal(self, newval):
        if type(newval)!=bool:
            raise ValueError("You are trying to assign non-boolean value to the proposition")
        else:
            self.val=newval

As you can understand, Prop objects should be regarded as propositions with boolean value ascribed to each one of them. Also I have defined a standard boolean function, implication:

def impl(p, q):
    if p.getVal()==True and q.getVal()==False:
        return Prop(False)
    else:
        return Prop(True)

Now what I want to do is to define a function which will take some expression like this impl(impl(p,q), r) as the first of its arguments and a list of Propobjects ([p,q,r]) as the second one and check if this expression is true in regard with the propositions in the list. One important thing: if there's no proposition in the list which was mentioned in the expression, our program should regard this proposition as a false one. How can I do that?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...