Put
✖
Put
Details and Options

- Put starts writing output at the beginning of the file. It deletes whatever was previously in the file.
- Put inserts a newline (line feed) at the end of its output.
- expr>>filename is equivalent to expr>>"filename". 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.
- Put[…,OutputStream[…]] will append to the given stream.
- Put works with cloud and local objects.
- Put by default writes expressions in InputForm.
- Put[OutputForm[expr],"filename"] generates OutputForm.
- Put by default uses the character encoding "PrintableASCII" when creating a file. Add the option CharacterEncodingenc to specify a different encoding.
- When writing to an open file or an 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 Put.
- Put[…,File["file"]] is also supported.
Examples
open allclose allBasic Examples (1)Summary of the most common use cases
Compute a value to store in a temporary file:

https://wolfram.com/xid/0dejik-bvupiv

Set the current directory to one for temporary files:

https://wolfram.com/xid/0dejik-bqgnsu
Put the value of a into a file:

https://wolfram.com/xid/0dejik-czju2s
The file now contains the value:

https://wolfram.com/xid/0dejik-gqbkkz

https://wolfram.com/xid/0dejik-b9j8zj
Scope (4)Survey of the scope of standard use cases
Local objects can be used with Put and Get to store expressions persistently:

https://wolfram.com/xid/0dejik-3g94j


https://wolfram.com/xid/0dejik-djmveh

Cloud objects can be used with Put and Get to store expressions in the cloud:

https://wolfram.com/xid/0dejik-vqh2on


https://wolfram.com/xid/0dejik-rvo75y

Put expression in the file specified by the File object:

https://wolfram.com/xid/0dejik-juag3f


https://wolfram.com/xid/0dejik-xqumqa

https://wolfram.com/xid/0dejik-e46ohk
Create a file and open it for writing:

https://wolfram.com/xid/0dejik-tnb5jj

Put an expression to the stream:

https://wolfram.com/xid/0dejik-n3jwts

https://wolfram.com/xid/0dejik-0bc5fz

The file contents were written using the CharacterEncoding option of the stream:

https://wolfram.com/xid/0dejik-xuoion
Options (1)Common values & functionality for each option
CharacterEncoding (1)
By default, the encoding "PrintableASCII" is used when writing to files:

https://wolfram.com/xid/0dejik-6qhu2b
Special characters are written out as long names, which ensures they can be read on any system:

https://wolfram.com/xid/0dejik-fle0ve

Specify the common encoding "UTF-8":

https://wolfram.com/xid/0dejik-uacv0l
Special characters are written directly in the encoding, saving space at the cost of portability:

https://wolfram.com/xid/0dejik-7g2b46

Properties & Relations (2)Properties of the function, and connections to other functions
Put overwrites any existing file contents:

https://wolfram.com/xid/0dejik-dq2hgm

https://wolfram.com/xid/0dejik-jb077o
Only the second expression is in the file:

https://wolfram.com/xid/0dejik-c8kv6v
Use PutAppend to add to an existing file:

https://wolfram.com/xid/0dejik-dp87h7

https://wolfram.com/xid/0dejik-i7i7wo
When writing to a stream, Put behaves essentially like PutAppend:

https://wolfram.com/xid/0dejik-hb4qum


https://wolfram.com/xid/0dejik-tamr01

https://wolfram.com/xid/0dejik-qwru9r

The file has all three expressions, not just the last one:

https://wolfram.com/xid/0dejik-hcuh00
Possible Issues (1)Common pitfalls and unexpected behavior
The form expr>>filename treats filename as a literal name, not an expression to be evaluated:

https://wolfram.com/xid/0dejik-pf1qwg


https://wolfram.com/xid/0dejik-8w0cxz
The file that was written is called "file", not the name contained in the variable file:

https://wolfram.com/xid/0dejik-cpitp3


https://wolfram.com/xid/0dejik-safzw7

Use the form Put[expr,filename] to write to the file whose name is stored in file:

https://wolfram.com/xid/0dejik-nw0sth

Wolfram Research (1988), Put, Wolfram Language function, https://reference.wolfram.com/language/ref/Put.html (updated 2016).
Text
Wolfram Research (1988), Put, Wolfram Language function, https://reference.wolfram.com/language/ref/Put.html (updated 2016).
Wolfram Research (1988), Put, Wolfram Language function, https://reference.wolfram.com/language/ref/Put.html (updated 2016).
CMS
Wolfram Language. 1988. "Put." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/Put.html.
Wolfram Language. 1988. "Put." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/Put.html.
APA
Wolfram Language. (1988). Put. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Put.html
Wolfram Language. (1988). Put. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Put.html
BibTeX
@misc{reference.wolfram_2025_put, author="Wolfram Research", title="{Put}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/Put.html}", note=[Accessed: 07-June-2025
]}
BibLaTeX
@online{reference.wolfram_2025_put, organization={Wolfram Research}, title={Put}, year={2016}, url={https://reference.wolfram.com/language/ref/Put.html}, note=[Accessed: 07-June-2025
]}