Try
if __name__ == '__main__': from [whatever the name of your package is] import one else: import one
Note that in Python 3, the syntax for the part in the else clause will be
from .. import one
Strike>
On the other hand, this probably will not solve your specific problem. I did not understand this question and thought that two.py starts as the main module, but it is not. And given the differences in the way Python 2.6 (without importing absolute_import from __future__ ) and importing Python 3.x pens, you won’t need to do this for Python 2.6 anyway, I don’t think so.
However, if you end up switching to Python 3 and plan to use the module as a package module and as a stand-alone script inside a package, it might be a good idea to keep something like
if __name__ == '__main__': from [whatever the name of your package is] import one
in mind.
EDIT: And now for a possible solution to your real problem. Either start PyLint from the directory containing your one module (possibly using the command line), or put the following code somewhere when starting PyLint:
import os olddir = os.getcwd() os.chdir([path_of_directory_containing_module_one]) import one os.chdir(olddir)
Basically, as an alternative to messing around with PYTHONPATH, just make sure the current working directory is the directory containing one.py when you import.
(Looking at Brian’s answer, you could probably assign the previous init_hook code, but if you do, you can just make an addition to sys.path , which it does, which is a bit more elegant than my solution.)
JAB Jun 17 '10 at 20:03 2010-06-17 20:03
source share