[Tutor] Interpackage access help

Francesco A. Queirolo faq at lanl.gov
Tue Feb 21 02:40:18 CET 2006


>Francesco A. Queirolo wrote:
>> Sorry about the double post but the first one was sent before I was
>> completed with my question.
>>
>> I have the following directory structure on Windows XP running python
>> 2.4.2 final:
>>
>> JavaInheritancePoly\
>>                    HierarchicalInheritancePoly.py
>>                    Animals\
>>                            __init__.py
>>                            Modules\
>>                                       __init__.py
>>                                       Animal.py
>>                            Test\
>>                                      __init__.py
>>                                       AnimalTest.py
>>
>> When in AnimalTest.py I would like to access animal. I have tried:
>>
>> from JavaInheritancePoly.Animals.Modules import Animal

>For the above to work you need __init__.py in JavaInheritancePoly\ and
>the dir containing JavaInheritancePoly\ must be in sys.path either
>because it is in the working directory or some other means.

>Kent


Kent,
Thanks for the speedy reply. I have successfully been able to append my
sys.path through the command:
sys.path.append('pathToJavaInheritancePoly\Animals\Modules')

so that I could run my AnimalTest.py from the Test directory.

However, I would like to be able to use a .pth file (due to its
unobtrusiveness and the fact that I don't have to type in
'sys.path.append()' every time I want to run the test) located in the Test
directory so that I can import Animals.Module.Animals from AnimalTest
while AnimalTest lies in the Test directory.

I have already tried an absolute path to:
'pathToJavaInheritancePoly\Animals\Modules'

I have also tried relative paths:
'..'
and
'../../'

neither of which have been successful.

Thanks,
Francesco

-- 
Francesco Queirolo
Safeguards Systems Group(N-4)
Los Alamos National Laboratory
TA 35-2 A156
+1 505 606 1960
faq at lanl.gov


More information about the Tutor mailing list