如果我在MS-DOS命令提示符窗口中键入此行:
ipy -X:ColorfulConsole
Run Code Online (Sandbox Code Playgroud)
IronPython按预期启动,启用了彩色控制台选项.但是,如果我在Windows PowerShell中键入相同的行,我会收到以下消息:
File -X: does not exist
Run Code Online (Sandbox Code Playgroud)
谁能解释我做错了什么?
我正在尝试使用IronPython的python包.如果我导入常规的python模块,一切正常.
但是,当我尝试执行以下操作时:
import win32ui
Run Code Online (Sandbox Code Playgroud)
我明白了:
No module named win32ui
Run Code Online (Sandbox Code Playgroud)
我已经通过IronPython.Runtime.Importer中的代码进行了搜索,并且没有提到.pyd
有人知道解决这个问题吗?
我有以下IronPython代码.
class Hello:
def __init__(self):
pass
def add(self, x, y):
return (x+y)
Run Code Online (Sandbox Code Playgroud)
我可以使用以下C#代码来使用IronPython代码.
static void Main()
{
string source = GetSourceCode("ipyth.py");
Engine engine = new Engine(source);
ObjectOperations ops = engine._engine.Operations;
bool result = engine.Execute();
if (!result)
{
Console.WriteLine("Executing Python code failed!");
}
else
{
object klass = engine._scope.GetVariable("Hello");
object instance = ops.Invoke(klass);
object method = ops.GetMember(instance, "add");
int res = (int) ops.Invoke(method, 10, 20);
Console.WriteLine(res);
}
Console.WriteLine("Press any key to exit.");
Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)
我可以使用动态DLR使这段代码更简单吗?
该IronPython的行动中书有在<15.4.4动态对象进行交互的未来>关于它的简单的解释,但我无法找到一些例子.
我附上程序的源/批处理文件. Program.cs …
我正在构建一个可以与IronPython自动化的C#WebKit Web浏览器,以帮助进行质量保证测试。我将使用IronPython创建测试计划,该计划将运行许多浏览器方法,提供参数并评估结果。
IronPython的大多数文档都说明了如何使用C#调用IronPython方法,但是我已经弄清楚了如何为方法设置参数,以及如何检索方法的返回值,但不能从同一方法中返回。您将在下面的示例中注意到,我将参数传递给一个方法,该方法依次设置一个类成员变量,然后使用另一个方法检索该值。
谁能建议一个更优雅的图案?
Run Code Online (Sandbox Code Playgroud)using System; using System.Windows.Forms; using IronPython.Hosting; using Microsoft.Scripting; using Microsoft.Scripting.Hosting; namespace PythonScripting.TestApp { public partial class Form1 : Form { private ScriptEngine m_engine = Python.CreateEngine(); private ScriptScope m_scope = null; //used to call funcs by Python that dont need to return vals delegate void VoidFunc(string val); public Form1() { InitializeComponent(); } private void doSomething() { MessageBox.Show("Something Done", "TestApp Result"); } private string _rslt = ""; private string getSomething() { return _rslt; } private void setSomething(string val) …
我正在编写一个将Ironpython函数作为参数的C#组件。
def test():
x=x+1
print "Test"
Run Code Online (Sandbox Code Playgroud)
C#:
var v = engine.Operations.Invoke(scope.GetVariable("test"));
Run Code Online (Sandbox Code Playgroud)
无功v返回null的print语句。它只有在我有的情况下才有效return(x)。我可以使用ironpython捕获打印语句吗?
评论和链接表示赞赏。另外,可以仅使用命令行捕获它吗?
我想将 Python 与 C# 集成。我发现了两种使用进程间通信和 IronPython 的方法
进程间通信需要在所有客户端计算机上安装 Python.exe,因此不是一个可行的解决方案。
我们开始使用 IronPython,但它现在只支持 2.7 python 版本。我们使用的是 3.7 版本。
以下代码我们尝试使用 IronPython:
private void BtnJsonPy_Click(object sender, EventArgs e)
{
// 1. Create Engine
var engine = Python.CreateEngine();
//2. Provide script and arguments
var script = @"C:\Users\user\source\path\repos\SamplePy\SamplePy2\SamplePy2.py"; // provide full path
var source = engine.CreateScriptSourceFromFile(script);
// dummy parameters to send Python script
int x = 3;
int y = 4;
var argv = new List<string>();
argv.Add("");
argv.Add(x.ToString());
argv.Add(y.ToString());
engine.GetSysModule().SetVariable("argv", argv);
//3. redirect output
var …Run Code Online (Sandbox Code Playgroud) 我在 pyRevit 环境中使用 Iron python,我的代码如下:
element_types = \
DB.FilteredElementCollector(doc)\
.OfCategory(DB.BuiltInCategory.OST_Walls)\
.WhereElementIsElementType()\ # getting family types not elements
.ToElements()
for ele in element_types:
print(ele.Name)
Run Code Online (Sandbox Code Playgroud)
根据 Revit API 文档,这应该可以工作,并且可能在 C# 中工作。ele.Name既可以作为 setter也可以作为 getter 使用。但是在 Ironpython 上面的代码失败,返回一个AttributeError: Name. 但是当我尝试时ele.Name = "new_family_type_name"它工作正常。
所以我的问题是如何进行ele.Name工作以获取家庭类型名称。
我刚刚有一个项目,我必须在Windows操作系统上执行以下操作:
我是一位经验丰富的C\C++程序员,但我认为这将是我开始学习脚本编写的最佳时机.
我想到的候选人是:(Python || Ruby)&& PowerShell.
这些是我能用IronPython + Powershell完成的事情吗?或者那里有更好的工具/语言吗?
PS:PowerShell是否意味着要取代VBScript?另外,现在C#,WPF和Powershell的存在对VB.net有什么好处呢?
对于快速变化的业务规则,我将IronPython片段存储在XML文件中.到目前为止,这已经很好了,但我开始达到我需要更多只有一行表达式的地步.
问题是XML和重要的whilespace不能很好地协同工作.在我放弃另一种语言之前,我想知道IronPython是否有其他语法.
http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET/CSharp_IP_2.6
string code = @"
print 'test = ' + test
class MyClass:
def __init__(self):
pass
def somemethod(self):
print 'in some method'
def isodd(self, n):
return 1 == n % 2
";
Run Code Online (Sandbox Code Playgroud)
是'@'C#的一部分还是IronPython添加的东西?如果是后者,你如何在C#中做到这一点,某种运算符重载(基本上我可以让'@'做我想做的事情等等)?示例实现会很棒.否则,这里发生了什么?
ironpython ×10
c# ×5
python ×5
powershell ×2
.net ×1
import ×1
pyd ×1
pyrevit ×1
python.net ×1
revit-api ×1
ruby ×1
scripting ×1