Given a trivial Python package with __init__.py
:
$ ls -R foo/
foo/:
__init__.py bar.py
$ cat foo/bar.py
def do_stuff(): pass
$ cat foo/__init__.py
from .bar import *
I am surprised that it foo.bar
is determined:
>>> import foo
>>> foo.bar
<module 'foo.bar' from 'foo/bar.pyc'>
My understanding from x import *
is that it does not define x
in the current area. For instance:
>>> from abc import *
>>> abc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'abc' is not defined
Why is foo.bar
defined in my first example, although I haven't import bar
inside __init__.py
?
source
share