Python can only find modules on your PYTHONPATH. See this question for how to set it.
Modules can be at top level, or in a package. If you run python bar/b.py, the directory that b.py is in is implicitly added to the Python path. The directory that foo/ and bar/ are in is unknown to Python, let alone the one that contains a.py.
You can add './foo' to the PYTHONPATH. Then 'import a' will work.
If you want 'import foo.a' to work, then 'foo' must be a package, and it must be possible to find it. To do so, add '.' (the directory containing foo/' to the Pythonpath, and place an empty file named __init__.py
(note that's double underscores) in the same directory as a.py. That makes foo a package, and foo.a a module in that package.