Python
EvalMember
evaluate a Python member reference
Calling Sequence
Parameters
Description
Examples
Compatibility
EvalMember(s,n)
s
-
string or Python object
n
string or name
The EvalMember command executes a class member operation, s.n, using the Python interpreter.
By default the value returned is converted into a Maple data structure. If no conversion is available, the return value will be an expression of type python, a Python object reference that can be used in subsequent calls to Python.
The syntax, s:-n is usually preferred, but, in rare circumstances where evaluation of s is non-standard such that s may not be defined prior to forming the s:-n expression, the EvalMember(s,n) command can be used to resolve s.
This function is part of the Python package, so it can be used in the short form EvalMember(..) only after executing the command with(Python). However, it can always be accessed through the long form of the command by using Python[EvalMember](..).
with⁡Python:
ImportModule⁡from bs4 import BeautifulSoup
htmldoc≔<html><body><h1>Great Novels</h1><ul><li><a href=\"http://MiguelDeCervantes.com\">Don Quixote</a><li><a href=\"http://FyodorDostoevsky.com\">Crime and Punishment</a><li><a href=\"http://AlexandreDumas.com\">The Count of Monte Cristo</a></ul></body></html>
htmldoc≔<html><body><h1>Great Novels</h1><ul><li><a href="http://MiguelDeCervantes.com">Don Quixote</a><li><a href="http://FyodorDostoevsky.com">Crime and Punishment</a><li><a href="http://AlexandreDumas.com">The Count of Monte Cristo</a></ul></body></html>
soup≔EvalFunction⁡BeautifulSoup,htmldoc,html.parser
soup≔<Python object: <html><body><h1>Great Novels</h1><ul><li><a href="http://MiguelDeCervantes.com">Don Quixote</a><li><a href="http://FyodorDostoevsky.com">Crime and Punishment</a><li><a href="http://AlexandreDumas.com">The Count of Monte Cristo</a></li></li></li></ul></body></html>>
Normally the :- operator can be used to reference structure members.
soup:-h1:-string
Great Novels
The following is equivalent to the above.
EvalMember⁡EvalMember⁡soup,h1,string
Here is a contrived example that will generate an error because link:-text is formed before link has a value
eval⁡link:-text,link=soup:-find⁡a
Using delayed evaluation and EvalMember makes the above work:
eval⁡EvalMember⁡link,text,link=soup:-find⁡a
Don Quixote
Here is an example of using EvalMember to construct a sequence:
seq⁡EvalMember⁡link,text,linkinsoup:-find_all⁡a
Don Quixote,Crime and Punishment,The Count of Monte Cristo
The Python[EvalMember] command was introduced in Maple 2018.
For more information on Maple 2018 changes, see Updates in Maple 2018.
See Also
Python:-EvalString
type/python
Download Help Document