Is there a way to share headers in python? i import the same things in different controllers in pylons.
+1
A:
You could put the "header" things into a module of their own and then, wherever you need it, do
from myheadermodule import *
sth
2010-04-20 20:59:30
Except that that form of import is generally considered bad practice, for good reasons. If you are new to Python, you are likely to get yourself into trouble using it. If your program structure is such that you need it, you can probably do better by revisiting that structure and improving it.
Peter Hansen
2010-04-20 23:06:55
@Peter: I'm not saying normal modules should generally be imported like that. I'm saying it would solve the specific described problem, which I understood as "how can I avoid to copy-paste the same `import` statements into lots of my modules". I don't think the normal reasons against `import *` would apply in this case. This interpretation of the question might be wrong though, since I don't really see how the accepted answer would solve that problem.
sth
2010-04-22 03:50:35
@sth, you're quite right that your answer directly addresses the question. I'm just warning the OP that he should seek an alternative to using this approach. It's not necessary in any well-designed system. A simple variation that is much better would be using `import myheadermodule as mh` and then accessing everything inside as `mh.foo` and `mh.bar`. Feel free to incorporate the warning and advice into your answer, if you agree.
Peter Hansen
2010-04-22 14:31:59