PyD - accessing D class fields in Python
mw
mingwu at gmail.com
Mon May 17 16:54:07 UTC 2021
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:
>> 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.
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/make_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/make_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!
More information about the Digitalmars-d-learn
mailing list