Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing from sub-folder hierarchy in python

i am trying to import specified modules from test_file hierarchy

something like :

test_case1.py
test_subsuite_2
test_sub_2.1.1.py
test_suite2

is it possible to do a run import on this hierarchy

/project/main.py
/project/test_files

test_files folder hierarchy is like this :

test_files
    test_suite1
        test_case1.py
        test_subsuite_1
            test_sub1_1.py
            test_sub1_2.py
        test_subsuite_2
            test_subsuite_2_1
                test_sub_2.1.1.py
            test_sub2_1.py
            test_sub3_2.py

    test_suite2
        test_case2.py
        test_subsuite2_1
            test_sub21_1.py
            test_sub21_2.py
        test_subsuite2_2
            test_sub22_1.py
            test_sub23_2.py
like image 875
Ragav Avatar asked Jul 16 '12 09:07

Ragav


1 Answers

Create an empty file called __init__.py in all you folders. Then you can import using . as a folder separator. Documentation here.

like image 107
Charles Beattie Avatar answered Sep 30 '22 14:09

Charles Beattie