Message Boards Message Boards


[✓] Export the contents of a list as a text file?

Posted 6 months ago
2 Replies
0 Total Likes

I have a list of text items that have been extracted from a Dataset. I want to Export these to a text file Unfortunately, when I export the file I get not just the text, but the FullForm.

I create the list thus:

output = Style[Text[#], LineIndent -> 0] & /@ Normal[pQuestions]

The formatting is actually irrelevant, it was just me experimenting, but I include it in case it is relevant. Executing output in the notepad, just shows the text, and that's what I want.

However, when I export the file thus:

Export["pQuestions.txt", output]

The file contains:

Style[Text["Loreum Ipsum etc etc"], LineIndent -> 0]

What am I doing wrong? Cheers Andy

2 Replies
Posted 6 months ago


Not sure what Normal[pQuestions] evaluates to. Assuming it is a list of strings

list = {"one", "two", "three"};
Export["list.txt", list];


Mapping Style[Text[#], LineIndent -> 0] over the list results in a list of expressions, which is why it is not working as expected

Style[Text[#], LineIndent -> 0] & /@ list // InputForm

(* {Style[Text["one"], LineIndent -> 0], Style[Text["two"], LineIndent -> 0], Style[Text["three"], LineIndent -> 0]} *)
Posted 6 months ago

Thanks Rohit, That makes sense. I was getting confused about how to produce a clean output. I discovered that if I saved as a pdf rather than text, I got closer to what I want.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract