Get
<<name
reads in a file, evaluating each expression in it and returning the last one.
Get[stream]
reads from a stream, evaluating each expression in it and returning the last one.
Details and Options
- If name is the name of a Wolfram Language context, ending with a ` context mark character, then Get will process this name to find the file to read.
- For a name of the form "context`", Get will by default search for the following files:
-
context.mx file in DumpSave format context.mx/$SystemID/context.mx file in DumpSave format for your computer system context.wl file in the Wolfram Language source format context/Kernel/init.wl kernel initialization file for a particular directory context/init.wl general initialization file for a particular directory context.m file in the Wolfram Language source format context/Kernel/init.m kernel initialization file for a particular directory context/init.m general initialization file for a particular directory - For a name of the form "context`subcontext`", Get will by default search for "subcontext`" inside a directory named "context".
- If name is the name of a file, any extension must be included explicitly.
- <<"name" is equivalent to <<name. The double quotes can be omitted if the name contains only alphanumeric characters and the characters `, /, ., ∖, !, -, _, :, $, *, ~, and ?, as described in greater detail in "Operator Input Forms".
- The following options can be given:
-
CharacterEncoding $CharacterEncoding what raw character encoding to use Method Automatic method to use for reading streams Path $Path directories in which to search for the given file - Syntax errors in Wolfram Language input files are reported in the standard form: filename: line: syntax error in expr. Get continues attempting to read a file even after a syntax error has been detected. However, if an error is detected, $Context and $ContextPath are reset to the values they had when Get was called.
- Get can read .nb notebook files, returning the low-level box constructs that represent them.
- Get[CloudObject[…]] can be used to get files from the cloud.
- Get[LocalObject[…]] can be used to get files from local persistent storage.
- Get[Databin[…]] gets the contents of a databin in the Wolfram Data Drop.
- When operating on a local file, the global variables $Input and $InputFileName are set to the file name and the full path of the file being read, respectively, during the execution of Get.
- With the Method option, the stream is opened using the given input stream method. This overrides the default way that Get resolves file names. The value of the method option can be any member of $InputStreamMethods.
Examples
open allclose allBasic Examples (2)
Scope (2)
Options (3)
CharacterEncoding (1)
Create a package in the encoding "ISO8859-7":
Read the package back in the same encoding:
By default, the value of $CharacterEncoding is used, which may produce errors and different results:
Method (1)
Force the first argument to be interpreted as a string containing a package:
With the default setting of Automatic, it would be interpreted as a file name:
Path (1)
By default, all directories on $Path are consulted when searching for a file:
Force only the current directory to be searched:
Properties & Relations (2)
Possible Issues (1)
The form <<name treats name as a literal file name, not an expression to be evaluated:
This looks for a file called "package", not for the file whose name is in the variable package:
Use the form Get[name] to load the file whose name is stored in the variable package:
Text
Wolfram Research (1988), Get, Wolfram Language function, https://reference.wolfram.com/language/ref/Get.html (updated 2019).
CMS
Wolfram Language. 1988. "Get." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2019. https://reference.wolfram.com/language/ref/Get.html.
APA
Wolfram Language. (1988). Get. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Get.html