Django可以使用“外部”与其他库链接的python脚本(NumPy,RPy2 ...) [英] Can Django use "external" python scripts linked to other libraries (NumPy, RPy2...)

查看:104
本文介绍了Django可以使用“外部”与其他库链接的python脚本(NumPy,RPy2 ...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对IT业务(严重)发展的世界至为新鲜,但我想到了一个经营理念,仍然试图使整体基础设施应该如何运作。

I am new to the world of IT business (serious) development but I have in mind a business idea and still trying to vizualize how the overall infrastructure should work.

我已经做了一些很好的技术研究来提供解决方案。我非常倾向于在服务器端使用Python,MySql,Django(Apache)和客户端的一些RIA(可能是Flex),因为我需要一些高级可视化功能(特别是在看到FLARE项目后)。

I have done some few research for a good technology to deliver the solution. I am very inclined to use Python, MySql, Django (Apache) on the server side and some RIA on the client side (probably Flex) as I need some advanced visualization capabilities (especially after seeing the FLARE project).

应用程序需要在数值/统计方面进行一些放置提升,并将R与Python(RPy2)+其他像NumPy集成在一起似乎是理想的。

The application requires some "heaving lifting" on the numerical / statistical side and integrating R with Python (RPy2) + other like NumPy seems to be ideal.

我不能得到这个东西(当然是因为我是新手)是以下:

The thing i cannot get so far (certainly because i am a newbie) is the following:

Django(单向或另一种)执行一个(外部)python脚本/程序,其中包含引用额外的库(NumPy ...)?

Can Django (one way or the other) execute an (external) python script / program which contain reference to the extra libraries (NumPy ...)?

ex:用户触发一个动作执行统计分析,Django接收请求,并应运行一些使用数据库中的数据的Python代码(使用R,NumPy ...),并将结果存储在数据库中。 Django访问DB数据并将其发送回客户端应用程序进行显示。

ex: user triggers an action to perform a statistical analysis, Django receives the request and should run some python code (using R, NumPy...) which uses the data in the database and store the results back in the DB. Django accesses the DB data and send it back to the client app to be displayed.

这是正确的逻辑还是完全关闭路径?

Is this the right logic or am i completely off path?

非常感谢您的专业知识。

Many thanks in advance for your expertise.

推荐答案

Django是一个Python程序。和任何其他Python程序一样,它将能够访问其他Python脚本/模块。那么问题是如何执行脚本。如果您的脚本显式定义了一个 main (或另一个起始点)函数,那么您可以像模块一样导入它,并调用 main

Django is a Python program. And like any other Python program it will be able to access other Python scripts/modules. The question then, is how to execute the script. If your script explicitly defines a main (or another starting point) function then you can merely import it as you would a module and call the main.

例如:

# my custom script. Located in my_script.py
# lots of functions

def main():
    # call functions in sequence.

# my django view.
from myscript import main as script_main
script_main()

如果你而是从命令行执行,然后查看子进程模块。如果要异步运行,那么 Celery 可能是您正在寻找的内容。

If you'd rather execute as if from the command line then look at the subprocess module. If you want to run it asynchronously then something like Celery might be what you are looking for.

这篇关于Django可以使用“外部”与其他库链接的python脚本(NumPy,RPy2 ...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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