Search code examples
pythonpython-3.ximportpython-importboost-python

how can I import [.myfolder.pyfile] as [something else]?


let's say I have

project
   |__ utilities
   |      |__ foo.py
   |
   |__ boost_extensions
   |      |__ myclass.cpp
   |      |__ myclass.so
   |
   |__ someotherstuff
   |      |__ bar.py      
   |
   |__ mylib.py
   |
   |__ __main__.py

Is it possible to do something like this in main.py

import .utilities.foo as Foo
# this function will pass Foo to C++ and initialize it to a global variable
initCppFunction(Foo)

I've tried this but it gives me an invalid syntax error (I'm trying to do this due to some problems with importing python modules from boost/python). Is there a way to do this?

Thanks


Solution

  • Use

    from .utilities import foo as Foo