0
votes

First of all, I'm sorry if this question could have been asked/answered somewhere but I've been searching for 2 days before ending here asking for help.

Here is the problem : I have a python file that needs to import another python file in another folder which in turn needs to import another python file in the same folder and the problem comes at that point.

Here is the problem :

The Main.py in the root folder (for instance .\Main.py) calls this line:

import ate_framework.ate_results.test_result_file

test_result_file.py then imports this line :

from ..ate_test_point import test_point
import test_result

Please note that all the files are there and working well.

test_result.py is in the same folder than test_result_file.py

What I did to see what is going on is to test with Python.exe and then ipy.exe for the same import statement:

import ate_framework.ate_results.test_result_file

IronPython issue this error :

"ImportError: No module named test_result"

Python doesn't give any error

I can't even understand why and how to fix that in order to use IronPython to launch the main script.

Can someone just help get over this?

Thanks,

2
Please consider formatting code statements with markdown, and provide complete information about the directory structure. - crazyGamer
Thanks for the input, I will look forward to achieve so! - Mr. Bone

2 Answers

1
votes

Ok, finally I found out a solution which is still working with relative paths. In IronPython, if you want to import a file in the same directory than the caller, you need to right it down like this :

from . import module

It is important to add the "from ." otherwise it fails.

This rule doesn't apply to Python itself but IronPython.

Hope this helps someone.

0
votes

Try importing using the actual file path instead. This way you (and python) know exactly which file you're referring to.