我需要使用Python(和py2exe,我猜)构建一个本机Windows应用程序.
功能要求是:
到目前为止,我已经确定了以下可能的工具包:
我之前没有使用过任何这些,所以我期待你就选择上述之一的适用性或缺陷提出建议.
非常感谢你的想法!
丰富
PS:我考虑并打折了Titanium和Air; 由于运行时空气耗尽,Titanium因为编译/部署模型而退出.
编辑:这是有希望的(阅读:在开发中)用于QT的LGPL Python绑定(为什么pyQT不能完成LGPL我不知道):http://www.pyside.org/
使用一些IronPython脚本作为插件的项目,使用C#编码的功能.在我的一个C#类中,我有一个类型为的属性:
Dictionary<int, float>
Run Code Online (Sandbox Code Playgroud)
我从IronPython代码中设置了该属性的值,如下所示:
mc = MyClass()
mc.ValueDictionary = Dictionary[int, float]({1:0.0, 2:0.012, 3:0.024})
Run Code Online (Sandbox Code Playgroud)
但是,当运行这段代码时,它会抛出以下异常:
Microsoft.Scripting.ArgumentTypeException was unhandled by user code
Message=expected Dictionary[int, Single], got Dictionary[int, float]
Run Code Online (Sandbox Code Playgroud)
为了使事情变得更奇怪,最初使用的是C#代码
Dictionary<int, double>
Run Code Online (Sandbox Code Playgroud)
但是我在IronPython中找不到"双重"类型,一想到就"浮动"并且工作正常,没有错误.但是现在它在两端使用float(应该从一开始就使用它)它会出错,并认为C#代码使用的是"Single"数据类型?!
我甚至在对象浏览器中检查了C#库,当然,它显示为使用"float"类型而不是"Single"
在IronPython中有任何方法可以强制将包含整数值的表达式计算为浮点数.例如,我喜欢这个表达方式
1/3
Run Code Online (Sandbox Code Playgroud)
被评估为
1./3.
Run Code Online (Sandbox Code Playgroud)
结果为0.333 ...
我需要这个通过IronPython在C#项目中创建一个简单的运行时表达式计算器.我无法强制用户输入带有尾随小数点的表达式.
IEnumerable<T>在IronPython中获取.net长度的最快方法是什么?Python标准len()函数似乎无法在其上运行。
我知道我能做
len(list(my_enumerable))
Run Code Online (Sandbox Code Playgroud)
要么
list(my_enumerable).Count
Run Code Online (Sandbox Code Playgroud)
但这可能比必要的要慢。
我有一个C#类看起来有点像:
public class MyClass
{
private Func<IDataCource, object> processMethod = (ds) =>
{
//default method for the class
}
public Func<IDataCource, object> ProcessMethod
{
get{ return processMethod; }
set{ processMethod = value; }
}
/* Other details elided */
}
Run Code Online (Sandbox Code Playgroud)
我有一个IronPython脚本,可以在应用程序中运行
from MyApp import myObj #instance of MyClass
def OtherMethod(ds):
if ds.Data.Length > 0 :
quot = sum(ds.Data.Real)/sum(ds.Data.Imag)
return quot
return 0.0
myObj.ProcessMethod = OtherMethod
Run Code Online (Sandbox Code Playgroud)
但是当ProcessMethod被调用(在IronPython之外)时,在这个赋值之后,运行默认方法.
我知道脚本是运行的,因为脚本的其他部分都有效.
我该怎么做?
我创建了一个IronPython的脚本,从Python库进口,如os,sys等以及.NET库.
它从我的Visual Studio IronPython解决方案中运行得非常好,但我需要部署它,以便其他没有安装IronPython或Python的人可以运行它.
我该怎么办?
我正在尝试使用IronPython通过C#.NET运行Python类,Python类导入的几个模块是:
import collections
import nltk.classify.util
Run Code Online (Sandbox Code Playgroud)
为了在运行IronPython时导入它们,我使用ScriptEngine的GetSearchPath集合来添加Python库位置的路径,如下所示:
ICollection<string> paths = pyEngine.GetSearchPaths();
string dir = @"C:\Python27\Lib\";
paths.Add(dir);
string dir2 = @"C:\Python27\Lib\site-packages\nltk\classify\";
paths.Add(dir2);
pyEngine.SetSearchPaths(paths);
Run Code Online (Sandbox Code Playgroud)
这似乎对集合 Module 运行良好,但不是nltk.classify.util,并且在调用ScriptEngine的Execute方法时出现以下错误:
没有名为nltk.classify.util的模块
即使是util模块也存在于上面指定的路径中.我认为这个问题与在Python类中指定导入的方式有关('.'分隔),只是不确定如何解决它.任何想法出错的地方?
我有一个简单的例子,我想从Ironpython访问(我来自'常规/理智'python')所以我正在努力将我的C++代码导入Ironpython.通常我只是使用SWIG,包装我的代码,导入并继续我的快乐方式
但是,由于Ironpython是C#而不是C语言,这使得这个过程变得更加困难
我如何为ironpython包装这个类(我还为此示例附加了我的swig文件,但这可能没用)
#include "minimal.h"
double average(std::vector<int> v) {
return std::accumulate(v.begin(), v.end(), 0.0) / v.size();
}
std::vector<double> half(const std::vector<double>& v) {
std::vector<double> w(v);
for (unsigned int i = 0; i<w.size(); i++)
w[i] /= 2.0;
return w;
}
void halve_in_place(std::vector<double>& v) {
std::transform(v.begin(), v.end(), v.begin(),
std::bind2nd(std::divides<double>(), 2.0));
}
Run Code Online (Sandbox Code Playgroud)
用头文件
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
double average(std::vector<int> v);
std::vector<double> half(const std::vector<double>& v);
void halve_in_place(std::vector<double>& v);
Run Code Online (Sandbox Code Playgroud)
我有一个swig i文件minimal.i,但意识到有很多问题发出一个swig.exe -c ++ -python"%(FullPath)",并且铁蟒实际上在导入时接受它.
%module transfervector
%{
#include "minimal.h"
%}
%include "std_vector.i"
// …Run Code Online (Sandbox Code Playgroud) 是否可以将Entity Framework 6与代码第一模式一起使用,并在C#和IronPython中编写模型?
背景是,c#core中定义了一些标准模型,并且必须在IronPython中定义一些自定义模型.
编辑
定制模型在我们的定制生产系统中定义.应该加载模型并将其添加到DbContext应用程序启动时.每个模型都是一个IronPython文件/模块,将从数据库加载(与所有其他脚本一样).
不工作的样品
Program.cs中
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IronPython_EF
{
class Program
{
// Private Member
private static SampleContext context;
static void Main(string[] args)
{
// Setup EntityFramework
context = new SampleContext();
// Create IronPython
var setup = Python.CreateRuntimeSetup(null);
var runtime = new ScriptRuntime(setup);
var engine = runtime.GetEngine("IronPython");
var scriptScope = engine.CreateScope();
// Set global var
scriptScope.SetVariable("DBContext", context);
// Load Model
ScriptSource modelSource …Run Code Online (Sandbox Code Playgroud) c# ironpython entity-framework dynamic-language-runtime sqlanywhere
我开始用Python编写应用程序,但我现在想切换到C#和UWP.我知道你不能用Python编写UWP应用程序,但我试图看看我是否可以用Python编写一些代码并从C#访问该代码.
例如,在Python中编写一个C#代码也可以访问的类.那可能吗?如果是这样,Python可以访问微软的UWP API吗?
主代码不会用Python编写; 那是不可能的.但是,C#和Python之间是否存在互操作性,可能还有IronPython(.NET的Python)?
我将如何设置这样的Visual Studio项目?我安装了Visual Studio for Python Studio,但没有内置选项将Python文件添加到我的UWP应用程序中.