So I am developing a class for vectorial calculations, and I overwrote the __mul__(self, b) function to do a Scalarproduct. Now whenever I write A * B it calculates as I want it to. So I would like to do the same with an x for the Crossproduct. Sadly there is no default x operator in python, it would probably just annoy you. But is there a way to create your own operator which ONLY works for my own class, but can otherwise be used in a code aswell (as a variable definition I mean)? Or maybe define *** as an operator?
1 Answer
Instead of just define an operator, you can write your own interpreter for your own language inside python. Basically, you need to create 4 modules
parser
environment
eval
repl
Then you can program with your own language within python.
read Peter Novig's article for a detailed example of a python LISP interpreter
__matmul__method, which is associated with the@operator. It's supposed to be for matrix multiplication, but that's not a hard & fast rule.