I could pull those dynamically from a text file containing ONLY the corresponding values, comma separated:
120, 200, 333, 88, 120, 300
I looked into File and saw File.use expects a function, but i guess putting a Pbind there is no good (or rather I did not know how to do that, supposing that’s possible).
Pretty cool, although I encountered some problems, surely my bad.
I get a nil after each line. Perhaps where carriage returns are? Does it matter if the file was made on Windows/Mac/Linux? I think different OSs deal with new lines differently. Not sure if this is in anyway related to this.
I thought those arguments (true, true) for skipEmptyLines and skipBlanks would actually help there, but i keep getting those “nil” after each line. Is there a way to make it ignore everything that’s not commas or numbers?
If i get it correctly, it creates a 2-dimensional array. I tried flattening it with .flat which of course removes the square brackets but I still get those nils for each of the brackets (i think?).
hi Nixie,
i guess this depends a lot on what exactly is in your file.
if i create it as below (adapted from the help examples), it works as i’d expect
Right, cause there are no line breaks there, I believe. As soon as you introduce line breaks, CSVFileReader gives you nils, from what I’ve been testing.
anyway, if it’s just the nils specifically, you can reject them like this:
~my = ~my.reject(_.isNil)
// or one time:
~my = CSVFileReader.readInterpret("aa.txt", true, true).flat.reject(_.isNil).postln;
// edit: or slightly more generally
~my = CSVFileReader.readInterpret("aa.txt", true, true).flat.reject(_.isNumber.not).postln;
// edit2: or slightly more elegantly
~my = CSVFileReader.readInterpret("aa.txt", true, true).flat.select(_.isNumber).postln;