I experience difficulties attempting to convert a list of rationals to textstring fractions with numerator divided by (i.e. '/') denominator, and outputting each on a subsequent line to a file (i.e. [fraction] '\n')...

The code:

(* ::::: GENERATE SCALA TUNING FILE (.scl) ::::: *)
scalaoctave = 
 StringReplace[#, "--" -> "/"]  & [ToString[Drop[octave, 1]]]
scala = OpenWrite["tetrachordian.scl"] 
WriteString[scala, "!tetrachordian.scl\nGenerated by tetrachordian \
WriteString[scala, Column[scalaoctave]]
(* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- *)

I appreciate the consideration and thank you in advance.


UPDATE: This is what eventually worked:

  contents = { {headline}, {"!"}, {identity}, {"!"}, {"7"}, {"!"}} ;
      ExportString[ Column[Rest[octave], "\n"], "Table"]] ;
    Export[name, contents, "Table"]  ; 
  • $\begingroup$ Why not use Export instead? For example, Export[file, Rest[octave], "Table"]? $\endgroup$ – Carl Woll Jan 26 at 22:08
  • $\begingroup$ Carl Woll: Excellent answer, and we are almost there! Your suggestion worked perfectly without the header. I tried the following to add the header to the file, and get it nearly perfect, except the fractions in octave are no longer each on their own line in the file. Here's what I tried: contents = { {"! tetrachordian.scl"}, {"!"}, {"Generated by \ tetrachordian wolframcloud/yadda/dadda/doo/dah"}, {"!"}, \ {"7"}, {"!"}} ; AppendTo[contents, # ] & [Rest[octave]] Export["tetrachordian.scl", contents, "Table"] $\endgroup$ – Francis from ResponseBase Jan 27 at 2:44

Your Answer

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

Browse other questions tagged or ask your own question.