---
title: "Get"
language: "en"
type: "Symbol"
summary: "<< 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]."
keywords: 
- .wl
- .m
- .mx
- wl
- m
- mx
- .wls
- wls
- decode
- functions
- input
- load file
- load package
- pipes
- reading
- command file
- script file
- RESTORE
- load
- readlib
- load
- loadlibrary
- loadobj
canonical_url: "https://reference.wolfram.com/language/ref/Get.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Files"
    link: "https://reference.wolfram.com/language/guide/Files.en.md"
  - 
    title: "Wolfram Language Expressions in Files"
    link: "https://reference.wolfram.com/language/guide/WolframLanguageExpressionsInFiles.en.md"
  - 
    title: "Local Objects"
    link: "https://reference.wolfram.com/language/guide/LocalObjects.en.md"
  - 
    title: "Wolfram Language Syntax"
    link: "https://reference.wolfram.com/language/guide/Syntax.en.md"
  - 
    title: "Structured Data in the Cloud"
    link: "https://reference.wolfram.com/language/guide/StructuredDataInTheCloud.en.md"
  - 
    title: "Using the Wolfram Data Drop"
    link: "https://reference.wolfram.com/language/guide/UsingTheWolframDataDrop.en.md"
  - 
    title: "File Operations"
    link: "https://reference.wolfram.com/language/guide/FileOperations.en.md"
  - 
    title: "Cloud Functions & Deployment"
    link: "https://reference.wolfram.com/language/guide/CloudFunctionsAndDeployment.en.md"
  - 
    title: "External Operations"
    link: "https://reference.wolfram.com/language/guide/ExternalOperations.en.md"
  - 
    title: "Wolfram Language File Formats"
    link: "https://reference.wolfram.com/language/guide/WolframLanguageFileFormats.en.md"
related_workflows: 
  - 
    title: "Load a Package"
    link: "https://reference.wolfram.com/language/workflow/LoadAPackage.en.md"
related_functions: 
  - 
    title: "Needs"
    link: "https://reference.wolfram.com/language/ref/Needs.en.md"
  - 
    title: "Read"
    link: "https://reference.wolfram.com/language/ref/Read.en.md"
  - 
    title: "CloudGet"
    link: "https://reference.wolfram.com/language/ref/CloudGet.en.md"
  - 
    title: "Install"
    link: "https://reference.wolfram.com/language/ref/Install.en.md"
  - 
    title: "RunThrough"
    link: "https://reference.wolfram.com/language/ref/RunThrough.en.md"
  - 
    title: "Put"
    link: "https://reference.wolfram.com/language/ref/Put.en.md"
  - 
    title: "FileNameSetter"
    link: "https://reference.wolfram.com/language/ref/FileNameSetter.en.md"
  - 
    title: "SystemDialogInput"
    link: "https://reference.wolfram.com/language/ref/SystemDialogInput.en.md"
  - 
    title: "FileNames"
    link: "https://reference.wolfram.com/language/ref/FileNames.en.md"
  - 
    title: "FindFile"
    link: "https://reference.wolfram.com/language/ref/FindFile.en.md"
  - 
    title: "FileNameJoin"
    link: "https://reference.wolfram.com/language/ref/FileNameJoin.en.md"
  - 
    title: "ToExpression"
    link: "https://reference.wolfram.com/language/ref/ToExpression.en.md"
  - 
    title: "NotebookGet"
    link: "https://reference.wolfram.com/language/ref/NotebookGet.en.md"
  - 
    title: "Input"
    link: "https://reference.wolfram.com/language/ref/Input.en.md"
  - 
    title: "NotebookRead"
    link: "https://reference.wolfram.com/language/ref/NotebookRead.en.md"
  - 
    title: "$Input"
    link: "https://reference.wolfram.com/language/ref/$Input.en.md"
  - 
    title: "$InputFileName"
    link: "https://reference.wolfram.com/language/ref/$InputFileName.en.md"
  - 
    title: "Once"
    link: "https://reference.wolfram.com/language/ref/Once.en.md"
related_tutorials: 
  - 
    title: "Wolfram Language Packages"
    link: "https://reference.wolfram.com/language/tutorial/ModularityAndTheNamingOfThings.en.md#3780"
  - 
    title: "External Programs"
    link: "https://reference.wolfram.com/language/tutorial/FilesStreamsAndExternalOperations.en.md#8182"
  - 
    title: "Setting Up Wolfram Language Packages"
    link: "https://reference.wolfram.com/language/tutorial/ModularityAndTheNamingOfThings.en.md#5934"
  - 
    title: "Reading and Writing Wolfram System Files"
    link: "https://reference.wolfram.com/language/tutorial/FilesStreamsAndExternalOperations.en.md#14387"
  - 
    title: "Files for Packages"
    link: "https://reference.wolfram.com/language/tutorial/ModularityAndTheNamingOfThings.en.md#26880"
  - 
    title: "Wolfram Language Scripts"
    link: "https://reference.wolfram.com/language/tutorial/FilesStreamsAndExternalOperations.en.md#686606077"
  - 
    title: "Stream Methods"
    link: "https://reference.wolfram.com/language/tutorial/StreamMethods.en.md"
---
# 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.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](https://reference.wolfram.com/language/tutorial/OperatorInputForms.en.md)".

* 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 (10)

### Basic Examples (2)

Load a package:

```wl
In[1]:= <<EquationTrekker`
```

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

```wl
In[2]:= Names["EquationTrekker`*"]

Out[2]= {"DifferentialEquationTrek", "EquationTrekker", "EquationTrekkerNonModal", "EquationTrekkerState", "InitializeGenerator", "PoincareSection", "TrekData", "TrekGenerator", "TrekParameters"}
```

---

Get Wolfram Language input from a file:

```wl
In[1]:= FilePrint["ExampleData/language"]

22*a*b+56*c+13*a*d

In[2]:= <<ExampleData/language

Out[2]= 22 a b + 56 c + 13 a d
```

The input is evaluated:

```wl
In[3]:= Block[{a = 1, b = 2, c = 3, d = 4}, <<ExampleData/language]

Out[3]= 264
```

### Scope (2)

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

```wl
In[1]:= Put[10!, LocalObject["myval"]]

Out[1]= LocalObject["file:///home/home1/user/.Wolfram/Objects/myval"]

In[2]:= Get[%]

Out[2]= 3628800
```

---

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

```wl
In[1]:= Put[10!, CloudObject["cval"]]

Out[1]= CloudObject["https://www.wolframcloud.com/obj/documentation/cval"]

In[2]:= Get[%]

Out[2]= 3628800
```

### Options (3)

#### CharacterEncoding (1)

Create a package in the encoding ``"ISO8859-7"`` :

```wl
In[1]:= package = Close[BinaryWrite[CreateFile[], ToCharacterCode["αβγ", "ISO8859-7"]]];
```

Read the package back in the same encoding:

```wl
In[2]:= Get[package, CharacterEncoding -> "ISO8859-7"]

Out[2]= αβγ
```

By default, the value of ``\$CharacterEncoding`` is used, which may produce errors and different results:

```wl
In[3]:= Get[package]
```

\$CharacterEncoding::utf8: The byte sequence {225,226} could not be interpreted as a character in the UTF-8 character encoding.

\$CharacterEncoding::utf8: The byte sequence {225,226} could not be interpreted as a character in the UTF-8 character encoding.

\$CharacterEncoding::utf8: The byte sequence {225,226} could not be interpreted as a character in the UTF-8 character encoding.

General::stop: Further output of \$CharacterEncoding::utf8 will be suppressed during this calculation.

```wl
Out[3]= áâã
```

Delete the package file:

```wl
In[4]:= DeleteFile[package]
```

#### Method (1)

Force the first argument to be interpreted as a string containing a package:

```wl
In[1]:= Get["2+2", Method -> "String"]

Out[1]= 4
```

With the default setting of ``Automatic``, it would be interpreted as a file name:

```wl
In[2]:= Get["2+2", Method -> Automatic]
```

Get::noopen: Cannot open 2+2.

```wl
Out[2]= $Failed
```

#### Path (1)

By default, all directories on ``\$Path`` are consulted when searching for a file:

```wl
In[1]:= Get["ExampleData/language"]

Out[1]= 22 a b + 56 c + 13 a d
```

Force only the current directory to be searched:

```wl
In[2]:= Get["ExampleData/language", Path -> "."]
```

Get::noopen: Cannot open ExampleData/language.

```wl
Out[2]= $Failed
```

### Properties & Relations (2)

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

```wl
In[1]:= FindFile["EquationTrekker`"]

Out[1]= "/Applications/Mathematica.app/Contents/AddOns/Packages/EquationTrekker/Kernel/init.m"
```

Load the file:

```wl
In[2]:= Get[%]
```

Verify that the EquationTrekker package was indeed loaded:

```wl
In[3]:= Names["EquationTrekker`*"]

Out[3]= {"DifferentialEquationTrek", "EquationTrekker", "EquationTrekkerNonModal", "EquationTrekkerState", "InitializeGenerator", "PoincareSection", "TrekData", "TrekGenerator", "TrekParameters"}
```

---

Ensure that an initialization file is read only once:

```wl
In[1]:= Once[Get["init.m"]]
```

### Possible Issues (1)

The form ``<<name`` treats ``name`` as a literal file name, not an expression to be evaluated:

```wl
In[1]:= package = "EquationTrekker`"

Out[1]= "EquationTrekker`"
```

This looks for a file called ``"package"``, not for the file whose name is in the variable ``package`` :

```wl
In[2]:= <<package
```

Get::noopen: Cannot open package.

```wl
Out[2]= $Failed
```

Use the form ``Get[name]`` to load the file whose name is stored in the variable ``package`` :

```wl
In[3]:= Get[package]
```

## See Also

* [`Needs`](https://reference.wolfram.com/language/ref/Needs.en.md)
* [`Read`](https://reference.wolfram.com/language/ref/Read.en.md)
* [`CloudGet`](https://reference.wolfram.com/language/ref/CloudGet.en.md)
* [`Install`](https://reference.wolfram.com/language/ref/Install.en.md)
* [`RunThrough`](https://reference.wolfram.com/language/ref/RunThrough.en.md)
* [`Put`](https://reference.wolfram.com/language/ref/Put.en.md)
* [`FileNameSetter`](https://reference.wolfram.com/language/ref/FileNameSetter.en.md)
* [`SystemDialogInput`](https://reference.wolfram.com/language/ref/SystemDialogInput.en.md)
* [`FileNames`](https://reference.wolfram.com/language/ref/FileNames.en.md)
* [`FindFile`](https://reference.wolfram.com/language/ref/FindFile.en.md)
* [`FileNameJoin`](https://reference.wolfram.com/language/ref/FileNameJoin.en.md)
* [`ToExpression`](https://reference.wolfram.com/language/ref/ToExpression.en.md)
* [`NotebookGet`](https://reference.wolfram.com/language/ref/NotebookGet.en.md)
* [`Input`](https://reference.wolfram.com/language/ref/Input.en.md)
* [`NotebookRead`](https://reference.wolfram.com/language/ref/NotebookRead.en.md)
* [`\$Input`](https://reference.wolfram.com/language/ref/$Input.en.md)
* [`\$InputFileName`](https://reference.wolfram.com/language/ref/$InputFileName.en.md)
* [`Once`](https://reference.wolfram.com/language/ref/Once.en.md)

## Tech Notes

* [Wolfram Language Packages](https://reference.wolfram.com/language/tutorial/ModularityAndTheNamingOfThings.en.md#3780)
* [External Programs](https://reference.wolfram.com/language/tutorial/FilesStreamsAndExternalOperations.en.md#8182)
* [Setting Up Wolfram Language Packages](https://reference.wolfram.com/language/tutorial/ModularityAndTheNamingOfThings.en.md#5934)
* [Reading and Writing Wolfram System Files](https://reference.wolfram.com/language/tutorial/FilesStreamsAndExternalOperations.en.md#14387)
* [Files for Packages](https://reference.wolfram.com/language/tutorial/ModularityAndTheNamingOfThings.en.md#26880)
* [Wolfram Language Scripts](https://reference.wolfram.com/language/tutorial/FilesStreamsAndExternalOperations.en.md#686606077)
* [Stream Methods](https://reference.wolfram.com/language/tutorial/StreamMethods.en.md)

## Related Guides

* [`Files`](https://reference.wolfram.com/language/guide/Files.en.md)
* [Wolfram Language Expressions in Files](https://reference.wolfram.com/language/guide/WolframLanguageExpressionsInFiles.en.md)
* [Local Objects](https://reference.wolfram.com/language/guide/LocalObjects.en.md)
* [Wolfram Language Syntax](https://reference.wolfram.com/language/guide/Syntax.en.md)
* [Structured Data in the Cloud](https://reference.wolfram.com/language/guide/StructuredDataInTheCloud.en.md)
* [Using the Wolfram Data Drop](https://reference.wolfram.com/language/guide/UsingTheWolframDataDrop.en.md)
* [File Operations](https://reference.wolfram.com/language/guide/FileOperations.en.md)
* [Cloud Functions & Deployment](https://reference.wolfram.com/language/guide/CloudFunctionsAndDeployment.en.md)
* [External Operations](https://reference.wolfram.com/language/guide/ExternalOperations.en.md)
* [Wolfram Language File Formats](https://reference.wolfram.com/language/guide/WolframLanguageFileFormats.en.md)

## Related Workflows

* [Load a Package](https://reference.wolfram.com/language/workflow/LoadAPackage.en.md)

## Related Links

* [An Elementary Introduction to the Wolfram Language: Storing Things](https://www.wolfram.com/language/elementary-introduction/43-storing-things.html)

## History

* Introduced in 1988 (1.0) \| Updated in 1996 (3.0) ▪ 1999 (4.0) ▪ [2012 (9.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn90.en.md) ▪ [2014 (10.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn100.en.md) ▪ [2019 (12.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn120.en.md)