Ben Chuanlong Du's Blog

It is never too late to learn.

Builtin Objects Python

Python has built-in functions and object that users can use directly (no need to import). However, if you import another module which hide a built-in function or object, you cannot use it anymore. For example, sum is a built-in function in Python which can be used directly. However, if you use PySpark import SQL functions (from pyspark.sql.functions import *), the built-in function sum is hidden by the PySpark SQL function sum. You can still use the built-in function sum by importing the builtins module.

In [38]:
import builtins

builtins.sum([1, 2, 3])
Out[38]:
6
In [39]:
builtins.sum is sum
Out[39]:
True

Comments