WOLFRAM

ExternalOperation["Eval","code"]

represents an external evaluation of "code".

ExternalOperation["Eval","code",assoc]

represents an external evaluation of "code" with parameters given by assoc.

ExternalOperation["Call",func,arg1,arg2,]

calls the function func with the given arguments arg1, arg2, .

ExternalOperation["GetAttribute",obj,"attr"]

gets the attribute "attr" of obj.

ExternalOperation["SetAttribute",obj,"attr",val]

sets the attribute "attr" of obj to the given value val.

ExternalOperation["Cast",obj,"type"]

casts obj to the given "type".

ExternalOperation["op", arg1,arg2,]

represents the external operation named "op" using arguments arg1, arg2, .

Details

Examples

open allclose all

Basic Examples  (1)Summary of the most common use cases

Create an ExternalOperation to evaluate the code "2+2":

Out[1]=1

Run the operation using ExternalEvaluate:

Out[2]=2

Scope  (7)Survey of the scope of standard use cases

ExternalOperation does not evaluate:

Out[1]=1

You can use downvalues to accumulate arguments:

Out[2]=2

Run the operation using ExternalEvaluate:

Out[3]=3

Define an operator form for the "GetAttribute" operation:

Out[1]=1

Start a Python session:

Out[2]=2

Create an ExternalObject:

Out[3]=3

Use the operator over the object to the specified attribute:

Out[4]=4

The same can be done by creating a new operation:

Out[5]=5

The operation needs to be evaluated by using ExternalEvaluate:

Out[6]=6

Close the session:

External Operations  (5)

"Eval"  (1)

Run an ExternalOperation that represents arbitrary code evaluation in Python:

Out[1]=1

Use the second argument to pass an evaluation context:

Out[2]=2

"Call"  (1)

Define an ExternalOperation that creates a function in Python:

Out[1]=1

Call the function by running the ExternalOperation "Call":

Out[2]=2

Run the operation using ExternalEvaluate:

Out[3]=3

Any argument of the "Call" operation can be an ExternalOperation:

Out[4]=4

Arguments can also be passed directly in ExternalEvaluate by doing:

Out[5]=5

The result is equivalent to running the following Python code:

Out[6]=6

"GetAttribute"  (1)

Start a Python session to work with dates:

Return an ExternalObject for a datetime object:

Out[2]=2

Extract the year attribute by using "GetAttribute":

Out[3]=3

The result is equivalent to running the following Python code:

Out[4]=4

Delete the session:

"SetAttribute"  (1)

Start a Python session to work with decimal numbers:

Get the context for the decimal module:

Out[2]=2

Set the precision to 6:

Check that the precision was set to 6:

Out[4]=4
Out[5]=5

The result is equivalent to running the following Python code:

Delete the session:

"Cast"  (1)

Create an ExternalObject that represents the current date:

Out[2]=2

Use "Expression" to return the object as a Wolfram Language expression:

Out[3]=3

The Cast operation can also run in ExternalObject subvalues:

Out[4]=4

The symbol Expression is a shortcut for the same:

Out[5]=5

Return the object as a string:

Out[6]=6

The symbol String is a shortcut for the same:

Out[7]=7

Return the object as an ExternalObject:

Out[8]=8

The symbol ExternalObject is a shortcut for the same:

Out[9]=9

The same can be achieved by using "ReturnType" in ExternalEvaluate:

Out[10]=10

Delete the session:

Properties & Relations  (5)Properties of the function, and connections to other functions

ExternalOperation can be used to extract the operation from an ExternalObject:

Out[1]=1

The same can be done with an ExternalFunction:

Out[2]=2

ExternalOperation can be used as an argument to ExternalFunction:

Out[1]=1

The same can be done by using ExternalEvaluate:

Out[2]=2

ExternalOperation can be used as an argument to ExternalObject:

Out[1]=1

The executed operation is identical to this one:

Out[2]=2

Which can be executed with ExternalEvaluate:

Out[3]=3

The result is equivalent to running the following Python code:

Out[4]=4

Create an ExternalObject to work with the sys module:

Out[1]=1

When a string is used, the "GetAttribute" operation is executed in most evaluators, including Python:

Out[2]=2

The result is equivalent to running an explicit "GetAttribute" operation:

Out[3]=3

Multiple operations can be concatenated using multiple arguments in ExternalObject:

Out[1]=1
Out[2]=2

Which can be written in a more compact way:

Out[3]=3
Wolfram Research (2024), ExternalOperation, Wolfram Language function, https://reference.wolfram.com/language/ref/ExternalOperation.html.
Wolfram Research (2024), ExternalOperation, Wolfram Language function, https://reference.wolfram.com/language/ref/ExternalOperation.html.

Text

Wolfram Research (2024), ExternalOperation, Wolfram Language function, https://reference.wolfram.com/language/ref/ExternalOperation.html.

Wolfram Research (2024), ExternalOperation, Wolfram Language function, https://reference.wolfram.com/language/ref/ExternalOperation.html.

CMS

Wolfram Language. 2024. "ExternalOperation." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ExternalOperation.html.

Wolfram Language. 2024. "ExternalOperation." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ExternalOperation.html.

APA

Wolfram Language. (2024). ExternalOperation. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ExternalOperation.html

Wolfram Language. (2024). ExternalOperation. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ExternalOperation.html

BibTeX

@misc{reference.wolfram_2025_externaloperation, author="Wolfram Research", title="{ExternalOperation}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/ExternalOperation.html}", note=[Accessed: 07-June-2025 ]}

@misc{reference.wolfram_2025_externaloperation, author="Wolfram Research", title="{ExternalOperation}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/ExternalOperation.html}", note=[Accessed: 07-June-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_externaloperation, organization={Wolfram Research}, title={ExternalOperation}, year={2024}, url={https://reference.wolfram.com/language/ref/ExternalOperation.html}, note=[Accessed: 07-June-2025 ]}

@online{reference.wolfram_2025_externaloperation, organization={Wolfram Research}, title={ExternalOperation}, year={2024}, url={https://reference.wolfram.com/language/ref/ExternalOperation.html}, note=[Accessed: 07-June-2025 ]}