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
    MethodAutomaticmethod 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 all close all

Basic Examples  (2)

Load a package:

In[1]:=
Click for copyable input

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

In[2]:=
Click for copyable input
Out[2]=

Get Wolfram Language input from a file:

In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=

The input is evaluated:

In[3]:=
Click for copyable input
Out[3]=

Scope  (2)

Options  (3)

Properties & Relations  (2)

Introduced in 1988
(1.0)
|
Updated in 2019
(12.0)