digitalmars.D.learn - PyD - accessing D class fields in Python
- clothlen (49/49) Mar 18 2019 Howdy;
- Bastiaan Veelo (4/32) Mar 19 2019 If that doesn’t work, maybe you find help by filing an issue on
- mw (16/53) May 17 2021 I filed the issue here (still no response yet):
- Imperatorn (2/7) May 17 2021 https://github.com/symmetryinvestments/autowrap
- mw (27/42) May 17 2021 Thanks, I just tried, but still cannot get access to class field:
- mw (2/4) May 18 2021 It's fixed now: pyd version >= 0.14.1
- Imperatorn (2/7) May 19 2021 👍
Howdy;
I'm trying to extend my Python program with D, but I'm having 
trouble accessing a D class's field/attribute/property/something.
My D file looks like this:
```
module simpletest;
import pyd.pyd;
import std.stdio;
class ExampleTest{
	int _a = 3;
	int a(){
		return _a;
	}
	void a(int a){
		this._a = a;
	}
	int b = 4;
}
extern(C) void PydMain() {
	module_init();
	wrap_class!(
		ExampleTest,
		Property!(ExampleTest.a),
		Property!(ExampleTest.b)
		// Member!("b")
	);
}
```
and my Python file looks like this:
```
"""Run with `pipenv run pytest -s tests/test_simple_test.py`."""
import simpletest
def test_class():
	test = simpletest.ExampleTest()
	assert None is print(test.a)
	assert test.a == 3
	test.a = 2
	assert test.a == 2
	assert None is print(test.b)
```
The first field, `a`, I can read, but `attribute 'b' of 
'simpletest.ExampleTest' objects is not readable`. `a` has a 
getter and setter function; do I have to make getters and setters 
for all fields I want to share with Python? That sounds like a 
lot of wasted space if so. The only examples at the Github 
(https://github.com/ariovistus/pyd/tree/master/examples) only 
seem to show it with getters and setters.
 Mar 18 2019
On Monday, 18 March 2019 at 22:25:10 UTC, clothlen wrote:Howdy; I'm trying to extend my Python program with D, but I'm having trouble accessing a D class's field/attribute/property/something. My D file looks like this: ``` module simpletest; import pyd.pyd; import std.stdio; class ExampleTest{ int _a = 3; int a(){ return _a; } void a(int a){ this._a = a; } int b = 4; } extern(C) void PydMain() { module_init(); wrap_class!( ExampleTest, Property!(ExampleTest.a), Property!(ExampleTest.b) // Member!("b")Maybe you need `Member!(“b”, “rw”)`?); }If that doesn’t work, maybe you find help by filing an issue on PyD.
 Mar 19 2019
On Tuesday, 19 March 2019 at 23:58:48 UTC, Bastiaan Veelo wrote:On Monday, 18 March 2019 at 22:25:10 UTC, clothlen wrote:I filed the issue here (still no response yet): https://github.com/ariovistus/pyd/issues/152 Just tried: ``` Member!("m_i", Mode!"rw"), ``` Still the same error: ``` /usr/local/lib/python3.6/dist-packages/pyd/infrastructure/pyd/ ake_wrapper.d(127): Error: no property shim for type pyd.struct_wrap.Member!("m_i", Mode!"rw") /usr/local/lib/python3.6/dist-packages/pyd/infrastructure/pyd/ ake_wrapper.d(137): Error: template instance pyd.make_wrapper.class_decls!(0u, Foo, Member!("m_i", Mode!"rw"), Init!int, Init!(int, int), Property!(i, Docstring!"A sample property of Foo."), BinaryOperatorX!("+", false, Guess), Def!(opSlice, PyName!"__iter__", Range function()), Def!(foo, Docstring!"A sample method of Foo."), Def!(a), Def!(b), Def!(c), Def!(d), Def!(e), Def!(f), Def!(g), Def!(h), Def!(j), Def!(k), Def!(l), Def!(m), Def!(n)) error instantiating ``` Anyone know how to expose D class data member to Python? Thanks!Howdy; I'm trying to extend my Python program with D, but I'm having trouble accessing a D class's field/attribute/property/something. My D file looks like this: ``` module simpletest; import pyd.pyd; import std.stdio; class ExampleTest{ int _a = 3; int a(){ return _a; } void a(int a){ this._a = a; } int b = 4; } extern(C) void PydMain() { module_init(); wrap_class!( ExampleTest, Property!(ExampleTest.a), Property!(ExampleTest.b) // Member!("b")Maybe you need `Member!(“b”, “rw”)`?); }If that doesn’t work, maybe you find help by filing an issue on PyD.
 May 17 2021
On Monday, 17 May 2021 at 16:54:07 UTC, mw wrote:On Tuesday, 19 March 2019 at 23:58:48 UTC, Bastiaan Veelo wrote:https://github.com/symmetryinvestments/autowrap[...]I filed the issue here (still no response yet): https://github.com/ariovistus/pyd/issues/152 [...]
 May 17 2021
On Monday, 17 May 2021 at 17:16:27 UTC, Imperatorn wrote:On Monday, 17 May 2021 at 16:54:07 UTC, mw wrote:Thanks, I just tried, but still cannot get access to class field: I build this example: https://github.com/symmetryinvestments/autowrap/tree/master/examples/pyd and test this: https://github.com/symmetryinvestments/autowrap/blob/master/examples/pyd/source/class_wrap.d class Bizzy { int _m; ... } ``` $ dub build --config=python36 $ ln -s lib/pyd/libpydtests.so pyd.so $ python3On Tuesday, 19 March 2019 at 23:58:48 UTC, Bastiaan Veelo wrote:https://github.com/symmetryinvestments/autowrap[...]I filed the issue here (still no response yet): https://github.com/ariovistus/pyd/issues/152 [...]bye(0)import pyd b = pyd.Bizzy(0) bTraceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'pyd.Bizzy' object has no attribute '_m' ``` Add `public` does not work either: ``` class Bizzy { public int _m; ... } ``` Any hints?b._m = 3
 May 17 2021
On Monday, 17 May 2021 at 16:54:07 UTC, mw wrote:I filed the issue here (still no response yet): https://github.com/ariovistus/pyd/issues/152It's fixed now: pyd version >= 0.14.1
 May 18 2021
On Tuesday, 18 May 2021 at 23:27:40 UTC, mw wrote:On Monday, 17 May 2021 at 16:54:07 UTC, mw wrote:👍I filed the issue here (still no response yet): https://github.com/ariovistus/pyd/issues/152It's fixed now: pyd version >= 0.14.1
 May 19 2021








 
  
  
 
 mw <mingwu gmail.com>
 mw <mingwu gmail.com> 