<< pyGetVar Python Interaction Mechanism in Scilab pyInvoke >>

Python Interaction Mechanism in Scilab >> Python Interaction Mechanism in Scilab > pyImport

pyImport

Import a module in Scilab environment

Calling Sequence

[mod =] pyImport(moduleName [, isNewVar]])

Arguments

moduleName

a string containing the module name.

isNewVar

a a boolean.

Description

Import a Python module in the Scilab environment. It is possible to append the module path to sys.path in using pyAddToPath. If isNewVar is true or omitted a new Scilab variable with the base module name (the name is the string before the first dot) is created, else a variable is returned.

It is possible to attach the module in Python environment as if 'import' was called in calling pyAttachModule(%t). In this case all the module name can be used. In the case where %T is given as second argument, the value of pyAttachModule as no effect.

Examples

pyImport urllib;
// a variable named urllib has been created
s = urllib.quote("hello world")

// a way to have an equivalent of the 'as' keyword
// import urllib2 as foo
foo = pyImport("urllib2", %f)
t = foo.unquote(s)

pyRemove urllib s foo t
pyAttachModule(%t)
pyImport os.path;
s = os.path.getsize(pathconvert("SCI/modules/elementary_functions/macros/cosh.sci", %f))

// In Python environment you can use os.path
pyEvalStr("print os.path.getsize(""" + pathconvert("SCI/modules/elementary_functions/macros/cosh.sci", %f) + """)");

pyRemove(os.path)
pyRemove s os

See Also

History

VersionDescription
5.4.0 Python module.

Report an issue
<< pyGetVar Python Interaction Mechanism in Scilab pyInvoke >>