a heisenbug

Chris Angelico rosuav at gmail.com
Mon Aug 28 16:08:24 EDT 2017


On Tue, Aug 29, 2017 at 4:59 AM, Stefan Ram <ram at zedat.fu-berlin.de> wrote:
>   This might be what one calls "heisenbug":
>
>   No attribute 'abc' is visible. One tries to
>   study it with "help". And next time it's there.
>   "help" /did/ help!
>
> Python 3.6.0 ...
>
>>>> import collections
>
>>>> isinstance( 'abc', collections.abc.Sequence )
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> AttributeError: module 'collections' has no attribute 'abc'
>
>>>> help(collections)
> Help on package collections: ...
>
>>>> isinstance( 'abc', collections.abc.Sequence )
> True

When you import "collections", you load up the package. If anything
subsequently runs "import collections.abc", the module gets loaded,
and is visible from the package. The help function does exactly that
import. It's a bit surprising but only an issue with interactive work.
(You won't use help() elsewhere.)

ChrisA



More information about the Python-list mailing list