如何将[.myfolder.pyfile]导入为[其他]? [英] how can I import [.myfolder.pyfile] as [something else]?

查看:63
本文介绍了如何将[.myfolder.pyfile]导入为[其他]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有

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

是否可以在 main .py

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

我已经尝试过了,但是它给了我一个无效的语法错误(由于从boost/python导入python模块存在一些问题,我试图这样做).有办法吗?

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?

谢谢

推荐答案

使用

from .utilities将foo导入为Foo

from .utilities import foo as Foo

这篇关于如何将[.myfolder.pyfile]导入为[其他]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆