Mark Ackerman wrote:
>
> Yes I got that to work but I want to specify the complete package
> on the import line. this is because there can be more than 1
> plotTest.py module in the sys.path.
>
> So taking your code I want to do something like:
>
> cachedir = "pythonCache/a/b/scripts"
> if cachedir not in sys.path:
> sys.path.append( cachedir )
> import pythonCache.a.b.scripts.plotTest
> pythonCache.a.b.scripts.plotTest.printHello()
>
> to make sure I get the correct plotTest module.
So you want to do make each of the directories in your cachedir
into a python package - that means they need to have __init__.py files:
path = "pythonCache/a/b/scripts"
# ensure there are __init__.py files in each directory
# ideally, these would be in the source of the cache...
while path:
try:
open( os.path.join( path, "__init__.py" ), "wa" ).close()
catch IOException, val:
print "unable to create __init__.py in", path, val
path, dir = os.path.split( path )
import pythonCache.a.b.scripts.plotTest
pythonCache.a.b.scripts.plotTest.printHello()
kb
|