# Add a line without quotes by means of PutAppend

I'd like to export string, for example, like this:

"ZT[1,1]={"blabla", 0, n+13, 4*g1*g2/3 + g2^2};"


to myfile.m and there i want to see:

ZT[1,1]={"blabla", 0, n+13, 4*g1*g2/3 + g2^2};


but no matter what I do, I get other results, for example, like this:

"ZT[1,1]={\"blabla\", 0, n+13 , 4*g1*g2/3 + \ g2^2}"


What I did:

PutAppend[StringJoin["ZT[",ToString[i],",",ToString[k],"]=" ,"{", ToString[Last[ReadList[StringJoin["!some command ","'",ToString[Z[i,k][[1]]],"'"],String]]] ,"}"], StringJoin["some_table_up_",ToString[somenumber],"_babam.m"]]


If I wrote ToExpression, I can get only:

{"blabla", 0, n+13 , 4*g1*g2/3 + g2^2}


but I need a variable before it.

Thank you so much!

• What's wrong with WriteString? That is exactly what you want to do, I think. Jul 18, 2018 at 0:19
• Nothing =), just among the abundance of mathematica commands, I did not reach it) Thank you! Jul 18, 2018 at 10:35

## 1 Answer

Put["first line", "tmp.m"]
PutAppend[
Unevaluated[ZT[1,1]={"blabla",0,n+13,4*g1*g2/3+g2^2};],
"tmp.m"
]
Import["tmp.m","String"]


"first line"

ZT[1, 1] = {"blabla", 0, n + 13, 4*g1*(g2/3) + g2^2};

If you must use a string instead of an expression, then you can do:

With[
{
str=ToExpression[
"ZT[1,1]={\"blabla\", 0, n+13 , 4*g1*g2/3 + \ g2^2}",
StandardForm,
Unevaluated
]
},

Put[1,"tmp.m"];
PutAppend[str, "tmp.m"]
]

Import["tmp.m", "String"]


1

ZT[1, 1] = {"blabla", 0, n + 13, 4*g1*(g2/3) + g2^2}

• Thank you for your answer! It helped me as well as option of solution suggested by b3m2a1! Jul 18, 2018 at 10:33