I'm trying to access lines of code from another Mathematica notebook using NotebookImport

NotebookImport[FileNameJoin@{NotebookDirectory[], "QA.nb"}, _]

Stuff in Notebook that I'm importing from: F[x_]:=x^Sqrt[2]+1 Trigonometry

My Output is :

   RowBox[{RowBox[{"F", "[", "x_", "]"}], ":=", 
     RowBox[{SuperscriptBox["x", SqrtBox["2"]], "+", "1"}]}]], "Code",
   CellChangeTimes -> {{3.79913*10^9, 3.79913*10^9}}, 
  CellLabel -> "In[22]:=", 
  ExpressionUUID -> 
   "8583411c-4a4d-4f21-86d8-ebfb497b6dfc"], "Trigonometry", 

Is there any command that would display simply the line of code or is there any way of simplifying the output to the original line of code?


Suppose you assign your Output to c, then

Cases[Cases[c, e_Cell :> MakeExpression[e, StandardForm]], 
  ExpressionCell[line_, "Code", ___] :> 
   ToString[Unevaluated@line, InputForm], -1] // First


"F[x_] := x^Sqrt[2] + 1"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.