Message Boards Message Boards

GROUPS:

How to Export the contents of a list as a text file

Posted 11 days ago
103 Views
|
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 11 days 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 10 days 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
Attachments
Remove
or Discard

Group Abstract Group Abstract