@@ -8,49 +8,43 @@ pythonnet - Python for .NET
8
8
|license shield | |pypi package version | |python supported shield |
9
9
|stackexchange shield |
10
10
11
- Python for .NET is a package that gives Python programmers nearly
12
- seamless integration with the .NET Common Language Runtime (CLR) and
13
- provides a powerful application scripting tool for .NET developers. It
14
- allows Python code to interact with the CLR, and may also be used to
15
- embed Python into a .NET application.
11
+ Python for .NET 是一个包,可以让 Python 程序员几乎无缝集成 .NET 公共语言
12
+ 运行时 (CLR),并为 .NET 开发者提供一个功能强大的应用程序脚本工具。它允许
13
+ Python 代码与 CLR 交互,也可以用于将 Python 嵌入到 .NET 应用程序中。
16
14
17
- Calling .NET code from Python
15
+ 在 Python 中调用 .NET 代码
18
16
-----------------------------
19
17
20
- Python for .NET allows CLR namespaces to be treated essentially as
21
- Python packages.
18
+ Python for .NET 允许将 CLR 命名空间当作真正的 Python 包。
22
19
23
20
.. code-block ::
24
21
25
22
import clr
26
23
from System import String
27
24
from System.Collections import *
28
25
29
- To load an assembly, use the ``AddReference `` function in the ``clr ``
30
- module:
26
+ 要加载程序集,请使用 ``clr `` 模块中的 ``AddReference `` 函数:
31
27
32
28
.. code-block ::
33
29
34
30
import clr
35
31
clr.AddReference("System.Windows.Forms")
36
32
from System.Windows.Forms import Form
37
33
38
- Embedding Python in .NET
34
+ 在 .NET 中嵌入 Python
39
35
------------------------
40
36
41
- - All calls to python should be inside a
42
- ``using (Py.GIL()) {/* Your code here */} `` block.
43
- - Import python modules using ``dynamic mod = Py.Import("mod") ``, then
44
- you can call functions as normal, eg ``mod.func(args) ``.
45
- - Use ``mod.func(args, Py.kw("keywordargname", keywordargvalue)) `` or
46
- ``mod.func(args, keywordargname: keywordargvalue) `` to apply keyword
47
- arguments.
48
- - All python objects should be declared as ``dynamic `` type.
49
- - Mathematical operations involving python and literal/managed types
50
- must have the python object first, eg. ``np.pi * 2 `` works,
51
- ``2 * np.pi `` doesn't.
52
-
53
- Example
37
+ - 所有对 python 的调用应该被包含在一个
38
+ ``using (Py.GIL()) {/* Your code here */} `` 块中。
39
+ - 使用 ``dynamic mod = Py.Import("mod") `` 导入 python 模块,然后你就可以
40
+ 像平常一样调用函数,例如 ``mod.func(args) ``。
41
+ - 使用 ``mod.func(args, Py.kw("keywordargname", keywordargvalue)) `` 或
42
+ ``mod.func(args, keywordargname: keywordargvalue) `` 来应用关键字参数。
43
+ - 所有 python 对象都应该被声明为 ``dynamic `` 类型。
44
+ - 涉及 python 和字面值/托管类型的数学操作必须先使用 python 对象,例如,
45
+ ``np.pi * 2 `` 有效,``2 * np.pi `` 不行。
46
+
47
+ 示例
54
48
~~~~~~~
55
49
56
50
.. code-block :: csharp
@@ -79,7 +73,7 @@ Example
79
73
}
80
74
}
81
75
82
- Output :
76
+ 输出 :
83
77
84
78
.. code ::
85
79
@@ -90,10 +84,9 @@ Output:
90
84
int32
91
85
[ 6. 10. 12.]
92
86
93
- Information on installation, FAQ, troubleshooting, debugging, and
94
- projects using pythonnet can be found in the Wiki:
87
+ 关于安装、常见问题、故障排除、调试和使用 pythonnet 项目的信息,可以在 Wiki 中找到:
95
88
96
- https://github.com/pythonnet /pythonnet/wiki
89
+ https://github.com/lidanger /pythonnet/wiki
97
90
98
91
.. |Join the chat at https://gitter.im/pythonnet/pythonnet | image :: https://badges.gitter.im/pythonnet/pythonnet.svg
99
92
:target: https://gitter.im/pythonnet/pythonnet?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
0 commit comments