如何在gae-python上导入父模型
main:.
├─a
│ ├─__init__.py
│ └─aa.py
├─b
│ ├─__init__.py
│ └─bb.py
└─cc.py
如果我在 aa.py 中,如何导入 cc.py ?
这是我的代码,但它是错误的:
from main import cc
我应该做什么。
感谢
更新
在正常的 python 文件(不在 gae 上)中
import os,sys
dirname=os.path.dirname
path=os.path.join(dirname(dirname(__file__)))
sys.path.insert(0,path)
import cc
print cc.c
,我可以使用此代码:但在 gae 上,它显示错误:
ImportError: No module named cc
main:.
├─a
│ ├─__init__.py
│ └─aa.py
├─b
│ ├─__init__.py
│ └─bb.py
└─cc.py
if i am in aa.py , how to import cc.py ?
this is my code ,but it is error :
from main import cc
what should i do .
thanks
updated
in normal python file (not on gae),i can use this code :
import os,sys
dirname=os.path.dirname
path=os.path.join(dirname(dirname(__file__)))
sys.path.insert(0,path)
import cc
print cc.c
but on gae , it show error :
ImportError: No module named cc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不明白您所显示的代码如何可能对您来说失败。为了重现您的问题,我构建了以下精简项目:
这是非空的 Python 文件:
正如预测的那样,它运行得很好,显示(无论是在 SDK 上本地运行时还是在 google 服务器上运行时) appspot.com):
因此您的代码部分中一定存在一些您没有向我们展示的其他错误。请通过复制这个小项目并在本地和 appspot.com 上尝试来确认这一点,并让我们知道它如何为您工作(或失败......?)。
I don't understand how the code you've shown can possibly be failing for you. Trying to reproduce your problem, I built the following pared-to-the-bone project:
Here are the nonempty Python files:
It runs just fine, as predicted, showing (both when run locally on the SDK and when run on google's servers at appspot.com):
So there must be some other error in parts of your code that you're not showing us. Please confirm this by reproducing this tiny project and trying it both locally and on appspot.com and let us know how it works (or fails...?) for you.