EvalMember - Maple Help

Python

 EvalMember
 evaluate a Python member reference

 Calling Sequence EvalMember(s,n)

Parameters

 s - string or Python object n - string or name

Description

 • 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](..).

Examples

 > $\mathrm{with}\left(\mathrm{Python}\right):$
 > $\mathrm{ImportModule}\left("from bs4 import BeautifulSoup"\right)$

$\mathrm{htmldoc}≔"

# Great Novels

"$

${\mathrm{htmldoc}}{≔}{"

# Great Novels

"}$

(1)
 > $\mathrm{soup}≔\mathrm{EvalFunction}\left(\mathrm{BeautifulSoup},\mathrm{htmldoc},"html.parser"\right)$

${\mathrm{soup}}{≔}{"

# Great Novels

>"}$

(2)

Normally the :- operator can be used to reference structure members.

 > $\mathrm{soup}:-\mathrm{h1}:-\mathrm{string}$
 ${"Great Novels"}$ (3)

The following is equivalent to the above.

 > $\mathrm{EvalMember}\left(\mathrm{EvalMember}\left(\mathrm{soup},\mathrm{h1}\right),\mathrm{string}\right)$
 ${"Great Novels"}$ (4)

Here is a contrived example that will generate an error because link:-text is formed before link has a value

 > $\mathrm{eval}\left('\mathrm{link}:-\mathrm{text}',\left\{\mathrm{link}=\mathrm{soup}:-\mathrm{find}\left('a'\right)\right\}\right)$

Using delayed evaluation and EvalMember makes the above work:

 > $\mathrm{eval}\left('\mathrm{EvalMember}'\left(\mathrm{link},"text"\right),\left\{\mathrm{link}=\mathrm{soup}:-\mathrm{find}\left('a'\right)\right\}\right)$
 ${"Don Quixote"}$ (5)

Here is an example of using EvalMember to construct a sequence:

 > $\left[\mathrm{seq}\left(\mathrm{EvalMember}\left(\mathrm{link},"text"\right),\mathrm{link}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{soup}:-\mathrm{find_all}\left('a'\right)\right)\right]$
 $\left[{"Don Quixote"}{,}{"Crime and Punishment"}{,}{"The Count of Monte Cristo"}\right]$ (6)

Compatibility

 • The Python[EvalMember] command was introduced in Maple 2018.