用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!"
以下是有关代码:(使用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!"
相关文章推荐
- 3.9 利用下列公式编程计算π的值:
- 系统的可靠度计算公式
- 遥感图像波段运算:分段公式叶面积指数计算
- I2C 上拉电阻选择计算公式
- 使用Pear的RPN库处理工资计算公式
- 利用公式计算π=4(1-1/3+1/5-1/7+1/9-...)的近似值,直到括号中最后一项的绝对值小于0.000001为止
- 利用ScriptEngineManager实现字符串公式灵活计算
- 协方差的意义和计算公式
- 【经典】计算字符串表示的公式的值
- QPS/QPS/PV/UV/服务器数量/并发数/吐吞量/响应时间计算公式
- 相机水平视角计算公式
- 公式解析和计算的实现
- 神经网络学习笔记-03-循环神经网络-反向传播计算公式的证明
- C# 字符串转换为计算公式
- 计算室内甲醛释放量的经验公式
- 图象速率及采集的计算公式
- 视频带宽计算公式(码流_分辨率_帧率)
- 广州打的费用计算公式
- 如何计算某一天是星期几?(Kim larsson公式)
- 斐波那契数列平方求和的计算公式及其几何证明