Message Boards Message Boards

0
|
3178 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

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

Posted 5 years ago

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

POSTED BY: Andrew Burnett
2 Replies
Posted 5 years ago

Andrew,

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

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

(*
one
two
three
*)

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 BY: Rohit Namjoshi
Posted 5 years 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.

POSTED BY: Andrew Burnett
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract