search

Home  >  Q&A  >  body text

Python 比较两个函数是否一致

高洛峰高洛峰2810 days ago697

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 14:00:48

    Okay~~I’m in over my head
    If it’s just a function comparison, just use ==
    But my situation here is a bit special
    So I can only compare names

    reply
    0
  • 阿神

    阿神2017-04-17 14:00:48

    You can study the source code of pysandbox

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 14:00:48

    For user-defined functions, just compare the function's __code__ attribute (Python 3) to see if it is in the allowed list. As for the built-in functions, since you want to restrict them, you won’t allow users to load the C library, right? Then just compare the function addresses.

    But don’t think that you can sit back and relax, it shouldn’t be difficult to bypass. For example, the sort function accepts a parameter as a function.

    reply
    0
  • Cancelreply