Python re-introduce the covered built-in function-Python tutorial

Source: Internet
Author: User
Recently, I encountered a problem when writing a python application: When a module is introduced, a custom int is automatically introduced to the namespace of python, which overwrites the intfunction that comes with python. because we need to use the python int, we have to find the method to re-introduce this int. fortunately, this problem is easy to solve. we only need to use _ builtins __:

From _ builtins _ import int as py_int

In this way, we can re-use the python int, but in this case it is called py_int.

The most common reason for overwriting a function or variable is that "*" is used for reference "*":

From something import *

When using import in this way, we cannot provide clear guidance on which variables or functions are introduced, or whether these variables or functions will overwrite the original variables or functions. therefore, this is one of the main reasons why "*" is not recommended during import.

In python 3, you can use builtins instead of _ builtins __.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.