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

Cannot convert to managed type #1900

Closed
Closed
@Tiehong

Description

@Tiehong

Environment

  • Pythonnet version: 3.0.0-rc4
  • Python version: 3.8
  • Operating System: Windows11
  • .NET Runtime: .NET Framework 4.8

Details

With the following code in C#, when a Python class hasgetitem() defined, it will be converted to an array (System.Object[]) in managed code:

List lst = new List();
using (Py.GIL())
{
using (var scope = Py.CreateScope())
{
scope.Set("lst", lst);
string text = @"
class DBRow:
definit(self, row, col_names):
self.row = row
self.col_names = col_names

def __getitem__(self, key):       if isinstance(key, int):        return self.row[key]    if key in self.col_names:        index = self.col_names.index(key)        return self.row[index]    else:        return None

col_names=['col1', 'col2', 'col3']
row=[1, '2', 3]

r = DBRow(row, col_names)
lst.Add(r)
";

                    var code = PythonEngine.Compile(text);                    scope.Execute(code);                }            }            string str = lst[0].GetType().ToString();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp