PutAppend
expr>>>filename
appends expr to a file.
PutAppend[expr1,expr2,…,"filename"]
appends a sequence of expressions expri to a file.
Details and Options
- PutAppend works the same as Put, except that it adds output to the end of the file, rather than replacing the complete contents of the file.
- PutAppend[…,OutputStream[…]] will append to the given stream.
- expr>>>"filename" is equivalent to expr>>>fileame. The double quotes can be omitted if the file name is of the form specified in "Operator Input Forms".
- It is conventional to use names that end with .wl or .m for files containing Wolfram Language input.
- PutAppend works with cloud objects.
- PutAppend by default uses the character encoding "PrintableASCII" when appending to a file. Add the option CharacterEncodingenc to specify a different encoding.
- When writing to an open file or to its OutputStream object, the current encoding of the output stream will be used by default. Add the option CharacterEncodingenc to temporarily change the encoding of the stream for the duration of PutAppend.
- PutAppend[…,File["file"]] is also supported.
Examples
open allclose allBasic Examples (1)
Scope (3)
Create a cloud object storing a value:
Append additional values to the cloud object:
Import the values back into the current session:
Append expression to the file specified by the File object:
Create a file and open it for writing:
Put several expressions to the stream:
The file contents were written using the CharacterEncoding option of the stream:
Options (1)
CharacterEncoding (1)
By default, the encoding "PrintableASCII" is used when writing to files:
Special characters are written out as long names, which ensures they can be read on any system:
Specify the common encoding "UTF-8":
Special characters are written directly in the encoding, saving space at the cost of portability:
Applications (1)
Create the first value that will be stored in a temporary file:
Set the current directory to one for temporary files:
Put the value of x in a file:
Update x and append the new value to the file:
The file now contains the two values:
Append successive iterates to the file in a loop:
Properties & Relations (2)
Possible Issues (1)
The form expr>>>filename treats filename as a literal name, not an expression to be evaluated:
The file that was written is called "file", not the name contained in the variable file:
Use the form PutAppend[expr,filename] to write to the file whose name is stored in file:
Text
Wolfram Research (1988), PutAppend, Wolfram Language function, https://reference.wolfram.com/language/ref/PutAppend.html (updated 2016).
CMS
Wolfram Language. 1988. "PutAppend." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/PutAppend.html.
APA
Wolfram Language. (1988). PutAppend. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/PutAppend.html