List

  • Import and Export provide various data conversion and formatting options for storing lists of numbers or strings.
  • Import automatically recognizes common number formats, including C and Fortran notations.
  • Numbers without decimal points are imported as integers.
  • Background

      Column of numbers or strings.
      Stores a list of numbers or strings as lines.
      Plain text format.
      Is essentially a single-column version of the "Table" format.

    Import and Export

    • Import["file","List"] imports a text file, returning each line as a string or a number.
    • Export["file",list,"List"] writes any list as a column of numbers or strings.
    • Import["file","List"] returns a list of strings or numbers, each representing a line of file.
    • Export["file",list,"List"] exports list as a column, writing the CForm of each element as a separate line.
    • Import["file",{"List",elem} ] imports the specified element from a "List" file.
    • Import["file",{"List",elem,suba,subb,}] imports a subelement.
    • Import["file",{"List",{elem1,elem2,}}] imports multiple elements.
    • The format "List" must be explicitly given.
    • Export["file",expr, {"List",elem}] creates a "List" file by treating expr as specifying element elem.
    • Export["file",{expr1,expr2,},{"List",{elem1,elem2,}}] treats each expri as specifying the corresponding elemi.
    • Export["file",expr,"List",opt1->val1,] exports expr with the specified option elements taken to have the specified values.
    • Export["file",{elem1->expr1,elem2->expr2,},{"List","Rules"}] uses rules to specify the elements to be exported.
    • See the reference pages for full general information on Import and Export.
    • ImportString and ExportString support the "List" format.

    Elements

    • General Import elements:
    • "Elements"list of elements and options available in this file
      "Rules"full list of rules for each element and option
      "Options"list of rules for options, properties, and settings
    • Data representation elements:
    • "Data"list of numbers or strings, each representing a line
      "Grid"list data as a Grid object
    • Import and Export use the "Data" element by default.

    Options

    • General Export options:
    • AlignmentNonehow data is aligned within table columns
      CharacterEncoding"UTF8"raw character encoding used in the file
    • Possible settings for Alignment are None, Left, Center, and Right.
    • General Import option:
    • CharacterEncoding"ASCII"raw character encoding used in the file
    • Import and Export option:
    • "EmptyField"""how to represent empty fields
    • Import options:
    • "CurrencyTokens"{{"$", "£", "¥", "€"}, {"c", "¢", "p", "F"}}currency units to be skipped when importing numerical values
      "DateStringFormat"Nonedate format, given as a DateString specification
      "IgnoreEmptyLines"Falsewhether to ignore empty lines
      "LineSeparators"{"r\n","n","\r"}string tokens taken to separate list elements
      "Numeric"Truewhether to import data fields as numbers if possible
      "NumberPoint""."string to use for a decimal point
      "NumberSigns"{"-","+"}strings to use for signs of negative and positive numbers
      "HeaderLines"0number of lines to skip at the beginning of the file
    • Import converts table entries formatted as specified by the "DateStringFormat" option to a DateList representation of the form {y,m,d,h,m,s}.
    • Empty lines and lines containing only whitespace characters are converted to an empty string by default. With "IgnoreEmptyLines" set to True, Import will skip empty lines.
    • With "Numeric"->False, numbers will be imported as strings in the form they appear in the file.
    • All common conventions for the encoding of newline characters are recognized with the default setting of "LineSeparators".

    Examples

    Basic Examples  (4)

    Import a text file as a list of strings:

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

    Import converts records to integers or reals if possible:

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

    Currency symbols are automatically omitted when importing as a list:

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

    Export a list of numbers using the "List" format:

    In[1]:=
    Click for copyable input
    Out[1]=
    Introduced in 1999
    (4.0)
    | Updated in 2012
    (9.0)