[Python.NET] Question about operators
J. Merrill
jvm_cop at spamcop.net
Thu Jun 7 16:37:48 CEST 2007
I don't know of a way for you to get the .Net operators to work from Python, but I certainly wouldn't want to try to read code that used + to do an operation that you seem to think should be named Or.
Why not add an Or method (or any name you want) to the BDDNode class, one that takes a BDDNode parameter, and write it so that others can figure out that code is calling a method of the BDDNode class?
BDDNode A = new BDDNode(whatever);
BDDNode B = new BDDNode(whatever);
A = A.Or(B)
gives more of an indication of what's happening than does
A+B
I'd have a bit of sympathy if you were trying to use + to call an operator that actually did some form of addition!
BTW, does BDDOr create a new BDDNode object and return it, or does it modify "this" and then return a reference to it? Those are very different ways of doing things...
At 05:20 PM 5/2/2007, Justin Frost wrote
>Hi Folks,
>Is there a way to write a C# class that has operators that work in Python? Currently, if I have a class with a method like the following:
>
>public static BDDNode operator +(BDDNode A, BDDNode B)
> {
> return A.BDDOr(B);
> }
>
>and try to add two BDDNode Objects in Python ith the "+" operator, I get the following:
>
>TypeError: unsupported operand type(s) for +: 'BDDNode' and 'BDDNode'
>
>Any way around this?
>
>Thanks,
>-Justin
J. Merrill / Analytical Software Corp
More information about the PythonDotNet
mailing list