简体   繁体   English

在python Google App Engine中导入自定义包

[英]Import custom package in python google app engine

OK guys I can't find a solution anywhere for my problem, and I hope the solution is a simple one. 好的,我无法在任何地方找到解决我问题的解决方案,我希望该解决方案很简单。 Previously I had a flat file system for my gae project with no folders. 以前,我的gae项目使用的是平面文件系统,没有文件夹。 I've been refactoring some code and I tried to put some in a folder. 我一直在重构一些代码,并试图将它们放在一个文件夹中。 I'm a bit new and I've never done something like this before, but nothing on the internet suggests that I shouldn't easily be able to move my files into a folder. 我有点新,以前从未做过这样的事情,但是互联网上没有任何东西表明我不应该轻易将文件移动到文件夹中。 I added the __init__.py file to the folder and I import the folder name from my main program. 我在文件夹中添加了__init__.py文件,并从主程序中导入了文件夹名称。 However when I attempt to access a particular function in one of the files, it chokes and says AttributeError: 'module' object has no attribute 'site1_ripper' 但是,当我尝试访问其中一个文件中的特定功能时,它感到窒息并说AttributeError: 'module' object has no attribute 'site1_ripper'

here is my file structure: 这是我的文件结构:

main.py
SiteCrawlers\
    __init__.py
    site1_ripper.py

here are important parts of the files: 这是文件的重要部分:

main.py

import SiteCrawlers
class Updater(webapp.RequestHandler):
    def get(self):
        SiteCrawlers.site1_ripper.siteCrawler()

site1_ripper.py

def siteCrawler()
    #stuff here

I think the problem is that you need to explicitly import site1_ripper unless it's specified in __init__.py . 我认为问题在于,除非在__init__.py指定了它,否则您需要显式导入site1_ripper。 Make your main import be: 使您的主要导入为:

import SiteCrawlers.site1_ripper

In your main file try: 在您的主文件中尝试:

from SiteCrawlers.site1_ripper import siteCrawler

class Updater(webapp.RequestHandler):
    def get(self):
        siteCrawler()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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