Any way to program custom syntax to python prompt? >> I want to edit matrices.

mosi skawanagi at gmail.com
Mon Dec 10 19:54:08 EST 2007


Python matrices are usually defined with numpy scipy array or similar.
e.g.
>>> matrix1 = [[1, 2], [3, 4], [5, 6]]
I would like to have easier way of defining matrices,
for example:
>>> matrix = [1, 2; 3, 4; 5, 6]

>>> matrix =
[ 1, 2;
  3, 4;
  5, 6;]

Any ideas how could this be done? The ";" sign is reserved, the "[ ]"
is used for lists.

Also, how to program custom operations for this new "class?"
matrix ???

For example:
>>> matrix + 2
[ 3, 4;
  5, 6;
  7, 8;]

Possibly with operator overloading?
I appreciate all your comments, directions, pointers.
mosi



More information about the Python-list mailing list