Python - Maple Programming Help

Home : Support : Online Help : Connectivity : Python : Python/ImportModule

Python

 ImportModule
 import a module in the Python environment

 Calling Sequence ImportModule(package)

Parameters

 package - string or sequence of strings

Description

 • The ImportModule command is used to import modules in the Python environment.
 • When package is a simple name, ImportModule(package) is equivalent to EvalString("import package",'output'='none').
 • When package already contains the string "import", usually as part of a more complicated import directive, then ImportModule(cmd) is the same as EvalString(cmd,output=none).
 • This function is part of the Python package, so it can be used in the short form ImportModule(..) only after executing the command with(Python). However, it can always be accessed through the long form of the command by using Python[ImportModule](..).

Examples

 > $\mathrm{with}\left(\mathrm{Python}\right):$
 > $\mathrm{ImportModule}\left("statistics"\right)$
 > $\mathrm{EvalString}\left("statistics.mean\left(\left[1,2,3\right]\right)"\right)$
 ${2}$ (1)
 > $\mathrm{ImportModule}\left("math as M"\right)$
 > $\mathrm{EvalString}\left("M.sin\left(0\right)"\right)$
 ${0.}$ (2)
 > $\mathrm{ImportModule}\left("from bs4 import BeautifulSoup"\right)$

Compatibility

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