Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Allow setting of the python module file#2044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
add test
  • Loading branch information
@bmello4688@filmor
bmello4688 authored andfilmor committedOct 16, 2023
commitc03d024a9623a8ed0e1978ed88c74d8fa840a6b9
35 changes: 35 additions & 0 deletionssrc/embed_tests/Modules.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -169,6 +169,41 @@ public void TestScopeClass()
}
}

/// <summary>
/// Create a class in the scope, the class can read variables in the scope.
/// Its methods can write the variables with the help of 'global' keyword.
/// </summary>
[Test]
public void TestCreateVirtualPackageStructure()
{
using (Py.GIL())
{
PyModule.FromString("scope",
"class Class1():\n" +
" def __init__(self, value):\n" +
" self.value = value\n" +
" def call(self, arg):\n" +
" return self.value + bb + arg\n" + //use scope variables
" def update(self, arg):\n" +
" global bb\n" +
" bb = self.value + arg\n" //update scope variable
, "test"
);


dynamic _ps = Py.Import("test.scope");
_ps.bb = 100;

dynamic obj1 = _ps.Class1(20);
var result = obj1.call(10).As<int>();
Assert.AreEqual(130, result);

obj1.update(10);
result = ps.Get<int>("bb");
Assert.AreEqual(30, result);
}
}

/// <summary>
/// Import a python module into the session.
/// Equivalent to the Python "import" statement.
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp