Title: How to implement __repr__ for a C# class to be used in python.net? · Issue #680 · pythonnet/pythonnet · GitHub
Open Graph Title: How to implement __repr__ for a C# class to be used in python.net? · Issue #680 · pythonnet/pythonnet
X Title: How to implement __repr__ for a C# class to be used in python.net? · Issue #680 · pythonnet/pythonnet
Description: 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 a Point class (a code snippet): public Point(double x, double y) { this.x = x; this.y =...
Open Graph Description: 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 a Point class (a code snippet): public Point(do...
X Description: 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 a Point class (a code snippet): public Point(do...
Opengraph URL: https://github.com/pythonnet/pythonnet/issues/680
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"How to implement __repr__ for a C# class to be used in python.net?","articleBody":"### Environment\r\n\r\n- Pythonnet version: 2.3.0\r\n- Python version: 2.7\r\n- Operating System: Windows 10\r\n\r\n### Details\r\n\r\nI have a C# class library which I use in Python. I have a `Point` class (a code snippet):\r\n\r\n public Point(double x, double y)\r\n {\r\n \tthis.x = x;\r\n \tthis.y = y;\r\n }\r\n \r\n public override string ToString()\r\n {\r\n \treturn $\"Point({x}, {y})\";\r\n }\r\n\r\nWhen I work with this class library in Python (in Python shell):\r\n\r\n \u003e\u003e\u003e p1 = Point(10,15)\r\n \u003e\u003e\u003e p1\r\n \u003cGeometry.Point object at 0x000000000558F828\u003e\r\n \u003e\u003e\u003e str(p1)\r\n 'Point(10, 15)'\r\n\r\nBecause I override the `ToString()`, when I run `str(p1)` I see my custom view of the object. However, when I just access a variable `p1`, then it goes to the `__repr__()` method under the hood which gives me ugly `\u003cGeometry.Point object at 0x000000000558F828\u003e`.\r\n\r\nIs there a method in C# class that is possible to override so that `pythonnet` would use that method when getting the `__repr__`?\r\n","author":{"url":"https://github.com/AlexArcPy","@type":"Person","name":"AlexArcPy"},"datePublished":"2018-06-03T09:40:54.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/680/pythonnet/issues/680"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5730f1d6-5d1f-4599-cb75-8acaec13b033 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E09A:19E64D:124DDA3:190EAD6:6971DCE1 |
| html-safe-nonce | 73b06464b7f38fe76db54896b80e0aa961d7f793083741f52e6ac3db01d06636 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMDlBOjE5RTY0RDoxMjREREEzOjE5MEVBRDY6Njk3MURDRTEiLCJ2aXNpdG9yX2lkIjoiNTU1MTI0NTYzNDMxNzc1NDU4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e1e567d07439a51aad0ee227608eea89ccfc0c7da61ae7c155dc863f1a0697a3 |
| hovercard-subject-tag | issue:328814476 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pythonnet/pythonnet/680/issue_layout |
| twitter:image | https://opengraph.githubassets.com/befad10a2f6029be642fe56c3b6e447278dda1251030717e468e0e4e1e2db7fd/pythonnet/pythonnet/issues/680 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/befad10a2f6029be642fe56c3b6e447278dda1251030717e468e0e4e1e2db7fd/pythonnet/pythonnet/issues/680 |
| og:image:alt | 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 a Point class (a code snippet): public Point(do... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | AlexArcPy |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7476eb4140129667a7530d10cfb7688f701883e35a4dcaa4673e3ec599af5199 |
| turbo-cache-control | no-preview |
| go-import | github.com/pythonnet/pythonnet git https://github.com/pythonnet/pythonnet.git |
| octolytics-dimension-user_id | 6050430 |
| octolytics-dimension-user_login | pythonnet |
| octolytics-dimension-repository_id | 14748123 |
| octolytics-dimension-repository_nwo | pythonnet/pythonnet |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 14748123 |
| octolytics-dimension-repository_network_root_nwo | pythonnet/pythonnet |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2cc0827c872b538cd08371730242ae4951d2d61a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width