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

How to implement __repr__ for a C# class to be used in python.net? #680

Closed
@AlexArcPy

Description

@AlexArcPy

Environment

  • Pythonnet version: 2.3.0
  • Python version: 2.7
  • Operating System: Windows 10

Details

I have a C# class library which I use in Python. I have aPoint class (a code snippet):

public Point(double x, double y){this.x = x;this.y = y;}public override string ToString(){return $"Point({x}, {y})";}

When I work with this class library in Python (in Python shell):

>>> p1 = Point(10,15)>>> p1<Geometry.Point object at 0x000000000558F828>>>> str(p1)'Point(10, 15)'

Because I override theToString(), when I runstr(p1) I see my custom view of the object. However, when I just access a variablep1, then it goes to the__repr__() method under the hood which gives me ugly<Geometry.Point object at 0x000000000558F828>.

Is there a method in C# class that is possible to override so thatpythonnet would use that method when getting the__repr__?

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