I recently came across this behaviour of Import
:
Export["new file.dat", {123,456,789}];
Import["new file.dat"]
Import["new*file.dat"]
The resulting Import
has an additional level of braces if a wildcard is present in the Import
instruction:
{{123}, {456}, {789}}
{{{123}, {456}, {789}}}
Although surprising, I'm guessing that the wildcard changes the heuristics Import
uses to guess the format it's reading in.
My question is, can an option be given to Import
so that it produces the same output for both the wildcard and exact file specification? Preferably two options can be found to consistently switch between the two output.
I've tried specifying "Table"
or "Data"
formats to Import
but the result stays different. Additionally, maybe someone knows how to find out which format Import
chooses when no option is specified. I know the result can be post-processed to be consistent, but I think that giving instructions to Import
would allow more flexibility in entering the file name.
This is on Mathematica 11.3 for Linux.
Import
returns a list of all matches it found (1 in your case). Not returning a list would be more inconsistent, because the same file name specification would then give differently structured results depending on the amount of files it found $\endgroup$ – Lukas Lang May 17 '18 at 14:47Import
output after the fact. $\endgroup$ – Musang May 17 '18 at 15:22