Wolfram: Load a Package or File

By Xah Lee. Date: . Last updated: .

Get (Load a File of WolframLang Code)

Get[filename]

🔸 SHORT SYNTAX: <<filename

  • Load a file of Wolfram language code, by file name.
  • filename can also be file fullpath.
  • If filename is not fullpath, It search the file in list of directories stored in the variable $Path. 〔see Wolfram: Search Paths $Path for Loading File

Get

Get[ "PlaneCurvePlot.wl" ]
Get[ "c:/Users/xah/git/PlaneCurvePlot/PlaneCurvePlot.wl" ]

Example. Load File in Current Notebook Dir

(* load a file, where the file is in the same dir as the current notebook *)

Get[StringJoin[NotebookDirectory[], "myfile.wl"]]

Example. Load File in Current Script Dir

(* load a file, where the file is in the same dir as the running script *)

Get[StringJoin[ DirectoryName[ $InputFileName ] , "myfile.wl"]]

〔see Wolfram: Get Script Path, Notebook Dir

Load a Package by Context Name

Another way to load a package, is to call Needs. This is a slightly higher level, based on Context Name , not a hard file path. It'll only load the file if the context is not already loaded.

Needs[ ContextName ]

Load a file if ContextName is not already in $Packages

The file name to load is based on ContextName to filename convention. You can give a second argument for a specific file name.

〔see Wolfram: Context (Namespace)

Once it figured out a file name, it calls Get to load the file.

in general, for Needs to work, you should put packages in the Wolfram Library Dir, in the Applications or Autoload subdirectory. 〔see Wolfram: Init Dir, Library Dir

Needs

Needs[ "PlaneCurvePlot`" ]

WolframLang, Package, Load File

WolframLang, Shell Scripting Tasks