writes expr to a file.
writes a sequence of expressions expri to a file.
creates an empty file with the specified name.
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.
Examplesopen allclose all
Basic Examples (1)
Put the value of a into a file:
Put expression in the file specified by the File object:
The file contents were written using the CharacterEncoding option of the stream:
Properties & Relations (2)
Possible Issues (1)
Use the form Put[expr,filename] to write to the file whose name is stored in file:
Wolfram Research (1988), Put, Wolfram Language function, https://reference.wolfram.com/language/ref/Put.html (updated 2016).
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. Retrieved from https://reference.wolfram.com/language/ref/Put.html