Because there's a path to it. Try this:
import sys
print sys.path
That should output all the places python uses as the starting direcctory to resolve module locations. So for example, if root is actually in /home/PulpFiction/root (or C:\Documents and Settings\PulpFiction\My Documents\root on windows), you'll see something like this:
['', '/usr/local/lib/python2.6/dist-packages', *more stuff*, '/home/PulpFiction/root']
or on windows:
['', 'C:\\python26\\site-packages', *more stuff here*, 'C:\Documents and Settings\PulpFiction\My Documents\root']
There are a few ways sys.path can be set (that I know of):
- The directory you run the script from
- Environment variable (PYTHONPATH to be exact)
- Windows Registry (on windows only obviously)
- Manually appending a path to the sys.path variable yourself in the code
I'm guessing the reason it work for you is you have a script in root (let's say main.py), and that script end up importing from both x and y. Since you're running the script in the root directory it's added to the python path, which allows from x import test to work.
EDIT
There's no __init__.py eh? You sure there isn't an __init__.pyc there (note the C in pyc)?