您的位置:首页 > 编程语言 > Python开发

用ironpython驱动你的计算公式

2007-08-18 20:14 183 查看
很多时候,很多应用都会使用到某些计算公式,而这些计算公式一段时间之后可能会调整。目前,一般处理的办法有硬编码、数据库表配置以及脚本。自ironpython发布之后,.net动态脚本的威力日增,以至于有DLR的诞生...

以下是有关代码:(使用ironpython自带的示例文件first.py)

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using IronPython.Hosting;

namespace IronPythonIntegrationDemo

这样,可以把动态脚本引擎集成进自己的程序里。当计算公式发生变化时,代码不需要修改,而只修改脚本即可。

我觉得还是蛮好的,起码在程序的扩展性上。

first.py文件内容如下:

#####################################################################################

#

# Copyright (c) Microsoft Corporation. All rights reserved.

#

# This source code is subject to terms and conditions of the Shared Source License

# for IronPython. A copy of the license can be found in the License.html file

# at the root of this distribution. If you can not locate the Shared Source License

# for IronPython, please send an email to ironpy@microsoft.com.

# By using this source code in any fashion, you are agreeing to be bound by

# the terms of the Shared Source License for IronPython.

#

# You must not remove this notice, or any other, from this software.

#

######################################################################################

def add(a, b):

"add(a, b) -> returns a + b"

return a + b

def factorial(n):

"factorial(n) -> returns factorial of n"

if n <= 1: return 1

return n * factorial(n-1)

hi = "Hello from IronPython!"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: