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.

Get["file","key"]

reads a file that has been encoded using Encode["source","file","key"].

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.mxfile in DumpSave format
    context.mx/$SystemID/context.mxfile in DumpSave format for your computer system
    context.wlfile in the Wolfram Language source format
    context/Kernel/init.wlkernel initialization file for a particular directory
    context/init.wlgeneral initialization file for a particular directory
    context.mfile in the Wolfram Language source format
    context/Kernel/init.mkernel initialization file for a particular directory
    context/init.mgeneral 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 $CharacterEncodingwhat raw character encoding to use
    Method Automaticmethod to use for reading streams
    Path $Pathdirectories 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 all

Basic Examples  (2)

Load a package:

This has set up definitions for several symbols in the EquationTrekker` context:

Get Wolfram Language input from a file:

The input is evaluated:

Scope  (2)

Local objects can be used with Put and Get to store expressions persistently:

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

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:

Delete the package file:

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)

FindFile["context`"] gives that file that Get["context`"] would load:

Load the file:

Verify that the EquationTrekker package was indeed loaded:

Ensure that an initialization file is read only once:

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:

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

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

BibTeX

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

BibLaTeX

@online{reference.wolfram_2024_get, organization={Wolfram Research}, title={Get}, year={2019}, url={https://reference.wolfram.com/language/ref/Get.html}, note=[Accessed: 23-November-2024 ]}