WOLFRAM

Enable JavaScript to interact with content and submit forms on Wolfram websites. Learn how
Wolfram Language & System Documentation Center
Wolfram Language Home Page »

PythonExpression

Background & Context

    • Code representation format for the Python programming language.
    • PythonExpression supports Python numbers, strings, lists, Booleans and dictionaries.
    • Plain text format.
    • Python was first released as a programming language in 1991.

Import & Export

Import Elements

  • General Import elements:
  • "Elements" list of elements and options available in this file
    "Summary" summary of the file
    "Rules" list of rules for all available elements
  • Details of elements...
  • "Data" the literal Python expression
  • ImportString uses the "Data" element by default.
  • The symbol Null is represented as the Python value "None".
  • Not all Python built-in types are supported. The supported Python types are:
  • tuple List an ordered sequence of values
    dictionary Association an association of keys and values
    int Integer arbitrary-sized integer
    long Integer arbitrary-sized integer
    float Real real-valued number
    complex Complex a complex number
    list List a sequence of values
    boolean True |False Boolean values
    string String a sequence of character values
    None Null null value

Examples

open allclose all

Basic Examples  (6)

Import a simple string:

Import a list:

Export to a string:

Import a dictionary as a Wolfram Language list:

Export an Association as a Python dictionary:

Import the result of evaluating external code in Python:

Confirm it is the same as using the "ReturnType" of "Expression" :

Possible Issues  (1)

"PythonExpression" internally starts and stops a Python session every time ImportString is called, which takes a substantial amount of time:

When performance is a concern, manually manage a Python session using ExternalEvaluate :

See Also

Import   Export   CloudExport   CloudImport

History

Introduced in 2017 (11.2)

Top [フレーム]

AltStyle によって変換されたページ (->オリジナル) /