python matrix output



I am trying to write a function that will allow me to take a
symbolically derived matrix from Maxima and copy and paste it into
Python for some numerical work.  Each element in the matrix could
simply be the fortran(element) so that exponents are handled
correctly.  Here is my function:

pythonmat(matin) := block (
  nc:length(matin[1]),
  nr:length(col(matin,1)),
  matstr:"array([",
  for i:1 thru nr do
      (if  (i > 1) then matstr:concat(matstr, ","),
      currow:matin[i],
      rowstr:"[",
      (for j:1 thru nc do
      	  (if  (j > 1) then rowstr:concat(rowstr, ","),
	  curfor:fortran(currow[j]),
	  rowstr:concat(rowstr,curfor))),
      rowstr:concat(rowstr,"]"),
      matstr:concat(matstr,rowstr)),
  matstr:concat(matstr,"])"));

The only problem is that I cannot capture the current fortran
expression for an element using:
curfor:fortran(currow[j]), because the output of the fortran command
is always done with the code printed to stdour.

Here is an example of my problem:
(%i103) pythonmat(J0);
      -sin(th1)*(cos(th2)*(cos(th3)*L3+L2)-sin(th2)*sin(th3)*L3+L1)
      cos(th1)*(-sin(th2)*(cos(th3)*L3+L2)-cos(th2)*sin(th3)*L3)
      cos(th1)*(-cos(th2)*sin(th3)*L3-sin(th2)*cos(th3)*L3)
      cos(th1)*(cos(th2)*(cos(th3)*L3+L2)-sin(th2)*sin(th3)*L3+L1)
      sin(th1)*(-sin(th2)*(cos(th3)*L3+L2)-cos(th2)*sin(th3)*L3)
      sin(th1)*(-cos(th2)*sin(th3)*L3-sin(th2)*cos(th3)*L3)
      0
      cos(th2)*(cos(th3)*L3+L2)-sin(th2)*sin(th3)*L3
      cos(th2)*cos(th3)*L3-sin(th2)*sin(th3)*L3
(%o103) array([[done,done,done],[done,done,done],[done,done,done]])

If a matrix is composed of [[A,B,C],[D,E,F]] then the output I need is
array([[A,B,C],[D,E,F]]).

Essentially, if this line actually captured the fortran code as a string
     curfor:fortran(currow[j]),
my code would work.

Can someone help me fix this please?

Thanks,

Ryan