Import Listing of Formats »

Import["file"]
imports data from a file, returning a complete Mathematica version of it.

Import["file", elements]
imports the specified elements from a file.

Import["http://url", ...] and Import["ftp://url", ...]
imports from any accessible URL.

DetailsDetails

  • 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.
  • Import elements determine which aspects of a file should be imported, and how they should be returned to Mathematica.
  • The following forms of element specifications can be given:
  • "format"take the file to be in the specified format
    elemimport a single element assuming the default format
    {"format",elem}import an element assuming the specified format
    {"comp1",...,"format",...}assume also compression formats (e.g. "GZIP")
    {elem1,elem11}import subelement of
    {elem1,elem11,...}import subelements of subelements
    {elem1,{elem11,elem12,...}}import several subelements of
    {elem1,n}import the n^(th) part of
  • Types of elements typically supported include:
  • "Elements"a list of names of elements
    "Rules"rules for the values of all elements
    "Options"rules for options, settings, meta-information, etc.
    "Data"data in a generic Mathematica form (list, string, etc.)
    "RawData"raw data as used in the format (e.g. indexed colors)
    "Image"raster image (for graphical formats)
    "Graphics"2D graphics (for graphical or geometry formats)
    "Graphics3D"3D graphics (for graphical or geometry formats)
    "Sound"sound (for sound formats)
    "Plaintext"plain text (for textual formats)
    "Grid"grid format (for arrays, spreadsheets, etc.)
  • If no element specification is given, Import will typically return expressions that display or operate as much as possible as they would in an external viewer of the file being imported. Graphical formats, for example, are by default returned as Graphics or Graphics3D expressions.
  • For some formats, there are options that specify details of how the import process should be performed; these are given as Import[source, elems, opts].
  • Names of Export options such as ImageSize can be given as elements for Import.
  • Import["file", ..., Path->path] searches for file on the specified path.
  • Import["!prog", "format"] imports data from a pipe.
  • When importing from a URL, Import can handle , , and .
  • 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 "" option which controls how Mathematica authenticates the identity of a server when establishing a network connection. By default Mathematica uses interactive authentication if necessary. With a setting "ServerAuthentication" -> False, Mathematica connects to the server without authentication. With "ServerAuthentication" -> True, Mathematica only connects to servers whose authenticity has been previously established.

ExamplesExamplesopen allclose all

Basic Examples (3)Basic Examples (3)

Import a complete GIF image file as an image object:

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

Find what elements are available to import:

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

Import the image size:

In[1]:=
Click for copyable input
Out[1]=
New in 4 | Last modified in 7
New to Mathematica? Find your learning path »
Have a question? Ask support »