开发者

Import shared module from folders

I have modules written in开发者_高级运维 c++ for python. For example, here is folders structure:

|Main/
|--SubMain/
|----Module1.so
|--SubMain2/
|----Module2.so
|----Module3.so

Now I want to import this into python like:

import Main.SubMain.Module1

First of all, I did recursively for all that folders:

import sys
sys.path.append(...)

And now I can do:

import Module1
import Module2
import Module3

But I want to specify the exact folder of the module. I tried to put __init__.py into all folders but this didn't help me. This way modules aren't visible for python. What's wrong?


In order to make something a package, you need to add __init__.py (not __input__.py) to the folders. So if you add __init__.py to Main, Submain1, and Submain2, then call sys.path.append with the parent of Main, you should be able to import as you desire.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜