'problem about Parameter transfer of jsonpath

I am running a code like below, but it's not what I want. real_path is defined at def check, so it's static.

#code before change
def check(path):
    with open(path,'r', encoding="utf-8") as f:
        file=json.load(f)
    real_path='C:\\Documents and Settings\\Administrator\\Local Settings\\Temp\\5.exe'
    call = jsonpath(file,"$.behavior.processes[?(@.process_path==real_path)].calls[?(@.category=='network')]")
    print(call)


if __name__ == "__main__":
    path="C:/users/hdl/Desktop/2min/2-5.json"
    #real_path = 'C:\\Documents and Settings\\Administrator\\Local Settings\\Temp\\5.exe'
    check(path)

Then I have changed like below, I have defined the real_path at main, thus it has worked.

def check(path):
    with open(path,'r',encoding="utf-8") as f:
        file=json.load(f)
    #real_path='C:\\Documents and Settings\\Administrator\\Local Settings\\Temp\\5.exe'
    call = jsonpath(file,"$.behavior.processes[?(@.process_path==real_path)].calls[?(@.category=='network')]")
    print(call)


if __name__ == "__main__":
    path="C:/users/hdl/Desktop/2min/2-5.json"
    real_path = 'C:\\Documents and Settings\\Administrator\\Local Settings\\Temp\\5.exe'
    check(path)

Does somebody know why?

What if I want to define at def check, what should I do?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source