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 all

Basic Examples  (1)

Set the current directory to one for temporary files:

Compute a value and save it in a file using Put:

The file now contains the value:

Compute another value and save it in the same file using PutAppend:

The file contains both results:

Reset the directory:

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:

Close 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:

Compare the last line with a direct computation:

Reset to the original directory:

Properties & Relations  (2)

PutAppend will create a file if the named file to append to does not exist:

Even though file was deleted, PutAppend recreated the file and stored the result in it:

PutAppend always adds to file contents:

Both expressions are in the file:

Use Put to overwrite existing file contents:

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:

Wolfram Research (1988), PutAppend, Wolfram Language function, https://reference.wolfram.com/language/ref/PutAppend.html (updated 2016).

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

BibTeX

@misc{reference.wolfram_2024_putappend, author="Wolfram Research", title="{PutAppend}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/PutAppend.html}", note=[Accessed: 05-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_putappend, organization={Wolfram Research}, title={PutAppend}, year={2016}, url={https://reference.wolfram.com/language/ref/PutAppend.html}, note=[Accessed: 05-November-2024 ]}