Python reintroduces the overwritten native function

  • 2020-04-02 13:49:49
  • OfStack

Fortunately, the problem is still very easy to solve. We just need to use the arbitration service.


from __builtins__ import int as py_int

So we can go back to using python's int, but at this point it's called py_int.

The most common reason a function or variable is overwritten is because it USES "*" in the reference:


from something import *

When using import in this way, we cannot clearly guide which variables or functions are introduced, and we cannot know whether these variables or functions will overwrite the original variables or functions. Therefore, this is one of the main reasons why "*" is not recommended when using import.

In python 3, you can use builtins instead of arbitration.


Related articles: