In the current working directory:
The package foo contains the module bar.py, along with an empty __init__.py file.
For argument's sake, the module bar.py contains the following code:
def print_message():
print 'The function print_message() prints this message'
print 'The module \"bar\" prints \"bar\"'
Expected behaviour upon import foo:
foo.barto printThe module "bar" prints "bar"foo.bar.print_message()to printThe function print_message() prints this message
Instead, I struggle with the import of the bar.py module:
On one hand, using
from foo import barthen allows to callbar.print_message()On the other hand, if I
import foo, thenfoo.baryields the error in the title:AttributeError: 'module' object has no attribute 'bar'(and so doesfoo.bar.print_message())
All the best rated questions on SO I've skimmed through so far, with regards to AttributeError, feature an answer related to something within the module, not the import itself. Also, Kernel is restarted between each attempt.
Question: Not a blocking point as such but it bugs me down not to understand that behaviour. I'm rather inexperienced, so what fondamental concept am I missing here? Thank you,