I have a project with a directory structure that looks like:
/foo/baz/__init__.py /bar/foo.py /bar/splat.py
Problem is, /bar/splat.py refers to the foo.baz module. This fails with the error No module named baz because it's trying to search for this module within /bar/foo.py. I don't want Python to search the bar module, I want to tell it to search the root foo module for baz. How do I do that? In Ruby you'd just prefix the identifier with :: (In this case, ::Foo::Baz), is there a Python eq开发者_StackOverflowuivalent to this?
In Python 2.5 and 2.6,
from __future__ import absolute_import
should change Python's import behavior to do what you want (if the very root, /, is on sys.path of course;-). This becomes the normal Python behavior in 2.7 (not released yet, but an early alpha is already tagged, if you're curious).
加载中,请稍侯......
精彩评论