NameError: name 'requests' is not defined ?

Steven D'Aprano steve at pearwood.info
Mon Jul 28 01:07:44 EDT 2014


On Mon, 28 Jul 2014 11:52:03 +0800, 水静流深 wrote:

> there is a simple file `mydown.py`  saved in
> `D:\Python34\Lib\site-packages`
>  there is only one line in mydown.py .
>  
>  import requests

Just because mydown has imported requests, doesn't mean it is visible 
everywhere. Each module is a separate namespace, so that 

    requests = "something"

inside module A doesn't break 

    import requests

inside module B.

Inside mydown you import requests, but you still need to import it in the 
interactive interpreter too. Don't worry, the second import will be very 
fast, once a module is imported once the second and subsequent times is 
very quick.


-- 
Steven



More information about the Python-list mailing list