从外部网址导入python模块 [英] Import python module from external url

查看:73
本文介绍了从外部网址导入python模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个 Python脚本,用于根据某些条件处理json数据.我还构建了一个自定义模块,该模块由用于检索json数据的方法和生成由已处理数据组成的json文件的方法组成.但是该模块文件存储在S3存储桶中,并且我需要将该模块导入到我的脚本中,以便我可以调用模块中定义的功能.

I am building a Python script for processing json data according to some criteria. Also I have built a custom module which consists of methods for retrieving json data and generation of json file which consist of processed data. But that module file is stored into S3 bucket and I need to import that module into my script so that I can invoke functions defined in module.

请向我建议有关从外部URL导入 python 模块的适当解决方案

Please suggest me appropriate solution regarding importing python module from external URL

推荐答案

好吧,如果在线模块全部位于一个文件中,则可以使用urllib2下载文件,然后将其导入:

Well, you could download the file using urllib2 and then import it, if the online module is all in one file:

from urllib2 import urlopen
r = urlopen('http://urlHere/fileHere')  
f = open('filenameToWrite', 'w')
f.write(r.read())
f.close()
import filenameWithout.PyInIt  

这篇关于从外部网址导入python模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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