How well do you know Python?

Carl Meyer carl at oddbird.net
Tue Jul 5 12:04:10 EDT 2016


On 07/05/2016 05:50 AM, Chris Angelico wrote:
> On Tue, Jul 5, 2016 at 9:33 PM, Peter Otten <__peter__ at web.de> wrote:
>> Chris Angelico wrote:
>>
>>> On Tue, Jul 5, 2016 at 6:36 PM, Peter Otten <__peter__ at web.de> wrote:
>>>> What will
>>>>
>>>> $ cat foo.py
>>>> import foo
>>>> class A: pass
>>>> print(isinstance(foo.A(), A))
>>>> $ python -c 'import foo'
>>>> ...
>>>> $ python foo.py
>>>> ...
>>>>
>>>> print?
[snip]
>> The intended lesson was that there may be two distinct classes
>>
>> __main__.A and foo.A
[snip]
> The two distinct classes problem is a very real one, and comes of
> circular (or not-technically-circular, as in the second case) imports.

It can also come of pathological setups where a path and its parent are
both on sys.path, so all import paths have an "optional" prefix (but you
actually get a different copy of the module depending on whether you use
that prefix).

Carl

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20160705/226ce8ba/attachment.sig>


More information about the Python-list mailing list