Import

Listing of Formats »

Import[source]

imports data from source, returning a Wolfram Language representation of it.

Import[source,"format"]

takes the file to be in the specified format.

Import[source,elements]

imports the specified elements from a file.

Import[path,,options]

uses the specified options.

Details

  • Import handles a large number of formats, each typically with many different possible elements. The possible formats are given in the list $ImportFormats, and in the guide "Listing of All Formats".
  • The format of a file is by default deduced from the file extension in its name, or by FileFormat from its contents.
  • In Import[source,], source can be any of the following:
  • "file" or File["file"]file name, searched for on $Path
    "url" or URL["url"]HTTP, HTTPS or FTP URL
    "!prog"import data from a pipe
    CloudObject[]a cloud object
    LocalObject[]a local object
  • Import elements determine which aspects of a file should be imported, and how they should be returned to the Wolfram Language.
  • The following elements specifications can be given:
  • elema single element
    {{elem1,elem2,}}multiple elements
    {elem1,sublelem1,subelem2,}subelements of subelements of elem1
  • When specifying the format, the following elements specifications can be given:
  • {"format",elem}a single element
    {"format",{elem1,elem2,}}multiple elements
    {"format",elem1,sublelem1,subelem2,}subelements of subelements of elem1
  • Elements supported by all formats are:
  • "Elements"a list of names of elements
    "Rules"rules for the values of all elements
    "Options"rules for options, settings, metainformation, etc.
  • If no element specification is given, every format defaults to the most suitable element. For instance, JPEG files are imported as Image objects by default.
  • Use Import[source,,options] to provide format-specific options that control the behavior of Import.
  • By default, local files are searched for on $Path. Use the option Path->path to specify other directories.
  • When importing a remote file, Import uses proxy and related settings specified in Preferences settings in the notebook front end or in your operating system environment.
  • Import generates a dialog if interactive authentication is required.
  • Import takes a "ServerAuthentication" option that controls how the Wolfram System authenticates the identity of a server when establishing a network connection. By default, the Wolfram System uses interactive authentication if necessary. With a setting "ServerAuthentication"->False, the Wolfram System connects to the server without authentication. With "ServerAuthentication"->True, the Wolfram System only connects to servers whose authenticity has been previously established.
  • New formats can be manually registered in the Wolfram Language. See "Developing an Import Converter".

Examples

open all close all

Basic Examples  (3)

Import a "GIF" file:

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

Find what elements are available to import:

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

Import a specific element of the file:

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

Scope  (2)

Generalizations & Extensions  (2)

Options  (2)

Introduced in 1999
(4.0)
|
Updated in 2018
(11.3)