My senior thesis project was a Python project, and I was coming from the Ruby world. Dear lord, I never got used to the import system. The fact that you have to throw in something like this to import anything local astounded me:
Circular dependencies tripped me up quite a bit too, but I can probably put that down to lack of experience in Python. But man, coming from a world where you could just do this, it was a bit of a shock:
The path insert is fairly horrible but I don't believe it's recommended.
Setting the PYTHONPATH environment variable can be useful in a local project (e.g. export PYTHONPATH=. in the root of your project), then using packages and absolute imports if you've got a lot of modules.
You can also import local modules just by using their name e.g. import my_module to import my_module.py from the same directory.
I find the Ruby require system a bit too close to PHP for my liking. I prefer that Python and Java abstract away the file system. However, using Bundler to manage your dependencies and put them onto the Ruby path at runtime is better than anything Python has.
Oh my god, the import/package system.
My senior thesis project was a Python project, and I was coming from the Ruby world. Dear lord, I never got used to the import system. The fact that you have to throw in something like this to import anything local astounded me:
Circular dependencies tripped me up quite a bit too, but I can probably put that down to lack of experience in Python. But man, coming from a world where you could just do this, it was a bit of a shock:
In Python3 it's a lot saner (still not perfect though)
The path insert is fairly horrible but I don't believe it's recommended.
Setting the
PYTHONPATH
environment variable can be useful in a local project (e.g.export PYTHONPATH=.
in the root of your project), then using packages and absolute imports if you've got a lot of modules.You can also import local modules just by using their name e.g.
import my_module
to importmy_module.py
from the same directory.I find the Ruby require system a bit too close to PHP for my liking. I prefer that Python and Java abstract away the file system. However, using Bundler to manage your dependencies and put them onto the Ruby path at runtime is better than anything Python has.
how about having the
__init__.py
file in the foo/ ?