17-12
Using Modules ( k import)
In the Python mode, you can use the functions below in addition to Python built-in functions.
Python standard math module and random module functions•
CASIO-original casioplot module functions (see page 17-18)•
However, to use a function contained in a module you have to first import (
import) the module.
import Syntax
Description
import <module name> Imports the module (py file) specified by
<module name>.
from <module name> import ½ Imports all of the elements* included in the
module specified by <module name>.
from <module name> import <element>
[, <element>]
Imports the specified elements (functions,
etc.) included in the module specified by
<module name>.
An element with a name that starts with an underscore (_) character cannot be imported.*
A single py file written by a py script is called a “module”. py files are imported using the •
same syntax as
import.
For an example of importing and using a py file, see “Sample 4: Importing a py File” in •
“Sample Scripts” (page 17-31).
Notation Examples:
import math (Imports the math module.)
from math import pi, sqrt (From the math module, imports
pi and sqrt only.)
If you use •
import to import a module, you need to include “<module name>.” before a
function in order to use that function. To use
pi within the math module, for example, it would
need to be written as “math.pi”.
When using •
from to import a module, do not use the syntax below.
<module name>.<function name>
Executing an import operation with this syntax will cause an error.