import mysteries

Ben Finney bignose+hates-spam at benfinney.id.au
Thu Jun 21 22:02:35 EDT 2007


David Abrahams <dave at boost-consulting.com> writes:

> I'm pretty comfortable with Python, but recently I'm constantly
> finding mysterious issues with import.  For example, looking at
>
>   http://genshi.edgewall.org/browser/trunk/genshi/filters/transform.py
>
> the examples use the symbol 'HTML' but it's not defined locally, it's
> not explicitly imported, and there's no import *.  Yet doctest will
> test this module and it passes with flying colors.  It turns out HTML
> is defined in genshi.input.  How do I know that?  I grepped for it.
> How does it become available to this module?

That's a mystery to me too. I can't see by looking at the module where
this 'HTML' name comes from, and as you say there is no import of
'genshi.input'.

Whatever the explanation, it's a violation of one of the strengths of
Python: namespaces. Names that appear in the current namespace (as
happens with 'from foo import *', and as seems to be happening here)
are bad programming style, for exactly the reason that they make the
code more difficult to understand.

-- 
 \       "bash awk grep perl sed, df du, du-du du-du, vi troff su fsck |
  `\                  rm * halt LART LART LART!"  -- The Swedish BOFH, |
_o__)                                            alt.sysadmin.recovery |
Ben Finney



More information about the Python-list mailing list