Question: Remove quote symbols when printing string to file

I have a code that outputs a long string of mathematics after various string replacements which I save into a file in the format of a Python function. Here is the code (for a 1 x 1 matrix):

restart:
Size:=1:
## This is the matrix which is generated in a string format
mat1:="Matrix(1, 1, [[-1/2*(A^8*hh*m3+6*A^7*B*hh*m3-2*A^7*hh*m3*z3+16*A^6*B^2*hh*m3-14*A^6*B]])":
## Open up file
filename2:=fopen(cat("Matrix", Size, "x", Size,"HH.py"),WRITE,TEXT): 

## Format file
fprintf(filename2,"import numpy as np\ndef myfuncHH(A,B):\n    z3 = 2\n    m3 = float('inf')\n    Mat_size = %a", Size): 
fprintf(filename2,"\n    arr = np.array([%a",mat1): 
fprintf(filename2,"],dtype=np.float64)"): 
fprintf(filename2,"\n    shape = ( Mat_size, Mat_size )\n    HH=arr.reshape( shape )\n    return HH"):
fclose(filename2):


This generates almost the exact output that is required:

 

import numpy as np
def myfuncHH(A,B):
    z3 = 2
    m3 = float('inf')
    Mat_size = 1
    arr = np.array(["Matrix(1, 1, [[-1/2*(A^8*hh*m3+6*A^7*B*hh*m3-2*A^7*hh*m3*z3+16*A^6*B^2*hh*m3-14*A^6*B]])"],dtype=np.float64)
    shape = ( Mat_size, Mat_size )
    HH=arr.reshape( shape )
    return HH

The part I want to remove is the "Matrix(1, 1, [   "Maths in here"   ])"]

 

I can use stringtools to tidy up most of this, but I am having trouble getting rid of the quotes of the string itself. I have tried escaping them and that does nothing. Is there a simple way to do this or will a regex have to be made?

 

- Yeti

Please Wait...