If you have a script like:
import requests
requests.get()
and you name it requests.py
you will get an attribute error saying that requests
has no attribute get
because Python is referring to the script name requests and that name doesn't have an attribute get
.
However, if I have this script:
import time
time.sleep()
and I name it time.py
, there won't be any error. Tried both on Python 2.7.11 and Python 3.5.3.
Why doesn't the same rule apply here?
because
time
is built-in, and request is a site package:Try printing the
__file__
attribute to see where the module is located:you get an error, but with
requests
you get the answeranother hint is given by
help(time.__loader__)
:for requests:
Anyway, don't call your modules as built-ins or library packages. In both cases you'll have problems.