If import an file in another file in the same folder.
file structure:
.
├── b
│ ├── c.py
│ ├── d.py
│ └── __init__.py
└── __init__.py
in d.py:
import b.c
print "import successfully"
update 1:
I use both
python d.py
and:
python b/d.py
the program cannot run and raise a ImportError.
To solve the problem, I use
sys.path.insert(0, realpath(path_join(dirname(__file__), '../')))
However, It doesn't seems like the standard way.
Like some famous project: tornado or some what, always using this structure. but don't have the insert line.
autotest tools such as sniffer, autonose can run such structure if the import sentence is in a unittest file.
I don't know why.
PEP328 or PEP366 don't give me a great solution about this.
PEP8 recommend me to do things like this way.
The question also occur when import another module (in another file) such as:
├── a
│ ├── e.py
│ └── __init__.py
├── b
│ ├── c.py
│ ├── d.py
│ └── __init__.py
├── __init__.py