Syntax

Fredrik Lundh fredrik at pythonware.com
Sun Nov 27 04:48:22 EST 2005


Terry Hancock wrote:

> > I don't think there are any *security* reasons, but
> > stylistically, "import os" is greatly preferred. When
> > someone else reads your code, they will immediately know
> > where getcwd() comes from.
>
> It's not a question of "security" in the usual sense, but
> the first syntax imports a lot of stuff into the current
> namespace, increasing the risk of unintentionally clobbering
> local names. So it's certainly "riskier" in the sense of
> "likely to cause bugs".

or just "likely to result in confusing error messages".

>>> from os import *
>>> f = open("myfile.txt", "r")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: an integer is required

</F>






More information about the Python-list mailing list