简体   繁体   中英

Google App Engine - Importing my own source modules (multiple files)

I am writing a GAE application and am having some difficulty with the following problem.

I've created multiple python files (say a.py and b.py) which are both stored in the same folder. I am able to call code in a.py or b.py by mapping URL's to them (using app.yaml). What I haven't figured out how to do is import the code from one into another.

Can anyone help me with the syntax and/or any config that is required here? For instance, I am under the impression that I can include the code from b.py in the file a.py by issuing the following statement in a.py

import b

I'm not having any success with this approach. Specifically I receive this error:

ImportError: No module named b

Any suggestions?

Thanks,

Matt

Have you tried importing as if you were starting at the top level? Like

import modules.b

If the files a.py and b.py aren't located, be sure to include the respective paths in sys.path .

import sys
sys.path.append(r"/parent/of/module/b")

请注意,GAE的常用模式不是每个都在app.yaml中独立映射,而是让一个“处理程序”脚本具有映射到它的所有(或除静态和特殊)URL,并具有该脚本导入a和b并使用他们定义的处理程序。

正如@toby所说,它必须像从顶层目录导入一样导入,并且必须将名为init .py的文件放在该文件夹中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM