1

Why python load my module from directory, even if the directory shouldn't be treated as a package (doesn't contains __init__.py)?

app
  main.py
  fake_module
    module.py

this works, even if fake_module doesn't contains __init__.py

import fake_module.module

If i would create regular fake_module with __init__.py and module.py file somewhere in sys.path, will be module.py loaded from this regular fake_module package?

I am using pycharm and python3.3

7
  • 1
    Are you 100% certain that you are looking at the right fake_module? What does print fake_module.module.__file__ give you? Commented Jun 15, 2013 at 16:33
  • @MartijnPieters: it gives that app/fake_module/module.py Commented Jun 15, 2013 at 16:38
  • @JBernardo: no i didn't Commented Jun 15, 2013 at 16:38
  • 1
    @Krab: and print fake_module.__file__ prints what? Commented Jun 15, 2013 at 16:40
  • 1
    @Krab: What does print type(fake_module) give? Commented Jun 15, 2013 at 16:42

1 Answer 1

7

It looks like the __init__.py is optional as of Python 3.3. See also PEP420.

Sign up to request clarification or add additional context in comments.

1 Comment

Bingo, I forgot about the new implicit namespaces support in 3.3.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.