Sunday 3 December 2017

python - Why is "import *" bad?

itemprop="text">

It is recommended to not to use
import * in Python.



Can anyone please share the reason for that, so
that I can avoid it doing next time?


class="post-text" itemprop="text">
class="normal">Answer






  • Because
    it puts a lot of stuff into your namespace (might shadow some other object from previous
    import and you won't know about it).


  • Because you don't know exactly what
    is imported and can't easily find from which module a certain thing was imported
    (readability).


  • Because you can't use
    cool tools like pyflakes to statically detect errors in your
    code.



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...