在python谷歌应用程序引擎中导入自定义包 [英] Import custom package in python google app engine

查看:92
本文介绍了在python谷歌应用程序引擎中导入自定义包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我无法找到解决问题的解决方案,我希望解决方案很简单。以前我有一个没有文件夹的gae项目的平面文件系统。我一直在重构一些代码,我试图把一些文件放在一个文件夹中。我有点新,我从来没有做过这样的事情,但互联网上没有任何事情表明我不应该轻易地将我的文件移动到文件夹中。我将 __ init __。py 文件添加到文件夹中,并从我的主程序导入文件夹名称。但是,当我尝试访问其中一个文件中的特定函数时,它会扼住并说 AttributeError:'模块'对象没有属性'site1_ripper'

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. 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. 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'

这里是我的文件结构:

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


推荐答案

我认为问题在于,除非在 __ init __。py 中指定,否则您需要显式导入site1_ripper。使您的主要导入为:

I think the problem is that you need to explicitly import site1_ripper unless it's specified in __init__.py. Make your main import be:

import SiteCrawlers.site1_ripper

这篇关于在python谷歌应用程序引擎中导入自定义包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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