import fails

Fredrik Lundh fredrik at pythonware.com
Sun Dec 5 22:19:17 CET 2004


Laszlo Zsolt Nagy wrote:

>>> Definitely. However, it would be better if the exception occurred on the
>>> bad assignment (e.g.  __all__ = [x])
>
>> it does happen on the bad assignment (i.e. from foo import *)
>
> Well, the traceback isn't useful. It does not tell you the line
> number not even the name of the module.

you're missing the point: the error happens on the "from - import" line,
which 1) assígns to all names in __all__, and 2) contains the name of
the module.

if you put your code in a module, you'll find that the traceback does tell
you the line number (for the import statement), and the name of the pro-
blematic module; example:

Traceback (most recent call last):
  File "myprogram.py", line 8, in ?
    from mymodule import *
TypeError: attribute name must be string

in interactive mode, the line number is usually 1, and the offending line is
the one you just typed.  which contains the name of the module.

this doesn't mean that the error message cannot be improved, of course,
but things aren't quite as bad as you make them sound.

</F> 






More information about the Python-list mailing list