ExternalOperation
Listing of External Evaluators »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
- ExternalOperation represents a remote procedure call to be executed in an ExternalEvaluate system, such as "Python", "Ruby", "NodeJS".
- Available operations "op" in ExternalOperation["op",…] vary from system to system.
- ExternalOperation[…] can be evaluated with ExternalEvaluate["system",ExternalOperation[…]].
- ExternalOperation["op",params…][args…] evaluates to ExternalOperation["op",args…,params…].
- ExternalObject[…][ExternalOperation[…]] is equivalent to ExternalEvaluate["system",ExternalOperation[…][ExternalObject[…]]].
Examples
open allclose allBasic Examples (1)
Create an ExternalOperation to evaluate the code "2+2":
Run the operation using ExternalEvaluate:
Scope (7)
ExternalOperation does not evaluate:
You can use downvalues to accumulate arguments:
Run the operation using ExternalEvaluate:
Define an operator form for the "GetAttribute" operation:
Create an ExternalObject:
Use the operator over the object to the specified attribute:
The same can be done by creating a new operation:
The operation needs to be evaluated by using ExternalEvaluate:
External Operations (5)
"Eval" (1)
Run an ExternalOperation that represents arbitrary code evaluation in Python:
"Call" (1)
Define an ExternalOperation that creates a function in Python:
Call the function by running the ExternalOperation "Call":
Run the operation using ExternalEvaluate:
Any argument of the "Call" operation can be an ExternalOperation:
Arguments can also be passed directly in ExternalEvaluate by doing:
The result is equivalent to running the following Python code:
"GetAttribute" (1)
Start a Python session to work with dates:
Return an ExternalObject for a datetime object:
Extract the year attribute by using "GetAttribute":
The result is equivalent to running the following Python code:
"SetAttribute" (1)
"Cast" (1)
Create an ExternalObject that represents the current date:
Use "Expression" to return the object as a Wolfram Language expression:
The Cast operation can also run in ExternalObject subvalues:
The symbol Expression is a shortcut for the same:
Return the object as a string:
The symbol String is a shortcut for the same:
Return the object as an ExternalObject:
The symbol ExternalObject is a shortcut for the same:
The same can be achieved by using "ReturnType" in ExternalEvaluate:
Properties & Relations (5)
ExternalOperation can be used to extract the operation from an ExternalObject:
The same can be done with an ExternalFunction:
ExternalOperation can be used as an argument to ExternalFunction:
The same can be done by using ExternalEvaluate:
ExternalOperation can be used as an argument to ExternalObject:
The executed operation is identical to this one:
Which can be executed with ExternalEvaluate:
The result is equivalent to running the following Python code:
Create an ExternalObject to work with the sys module:
When a string is used, the "GetAttribute" operation is executed in most evaluators, including Python:
The result is equivalent to running an explicit "GetAttribute" operation:
Multiple operations can be concatenated using multiple arguments in ExternalObject:
Text
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.
APA
Wolfram Language. (2024). ExternalOperation. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ExternalOperation.html