The
PYSC command extends Minitab's
functionality with Python but does not make Minitab an interactive
Python environment. As such, use Minitab
only with
Python scripts that complete without
interaction. For example, the
input()
function, which accepts input from
the keyboard while a script runs, does not work in Minitab. Interactivity in
Python takes many other forms, such as
plot.show()
and
keyboard.read_key()
.
For more information on Minitab's Python module, including Python code examples, go to Python API Reference.
All the files referenced in this guide are available in this .ZIP file: python_guide_files.zip.
Install and run Python before you attempt to integrate Python with Minitab Statistical Software. For assistance with the installation of Python, please consult with your organization's technical support department. Minitab Technical Support cannot assist with the installation of Python.
You can run the PYSC command in the Command Line pane. For general information about the Command Line pane, go to Command Line/History pane. For general information about using session commands, go to Session Command help.
Runs the Python script that you specify.
The default file extension for Python scripts is .PY. If the file extension is .PY, you do not need to type the file extension.
The optional argument
Args allows you to pass arguments
to the
Python script through
sys.argv[1:]
.
Args can be any text values
separated by a space. Enclose arguments in quotation marks. The default value
is
None
, which means that the script does
not receive any arguments.
In general, you use arguments to bring data from Minitab into Python. You can enter arguments in several ways. For example, you can use arguments that are identifiers for columns, matrices, or constants:
Minitab Session Command | Value in Python | Usage |
---|---|---|
|
|
Use the following function to retrieve the
column:
|
|
|
Use the following function to retrieve the
matrix:
|
|
|
Use the following function to retrieve the
constant:
|
You can also use arguments that are the names of columns, matrices, or constants in Minitab:
Minitab Session Command | Value in Python | Usage |
---|---|---|
|
|
Use the following function to retrieve the
column:
|
|
|
Use the following function to retrieve the
matrix:
|
|
|
Use the following function to retrieve the
constant:
|
You can also specify arguments to pass text to use in your Python code. You can pass text directly or in a constant.
Minitab Session Command | Value in Python | Usage |
---|---|---|
|
|
This case passed a value that cannot be
used with an
mtbpy 'get ' command. However,
Args are not limited to
only passing columns, matrices, and constants.
|
|
|
This case highlights that, although PYSC does not accept arguments that are not text values, you can pass a constant to PYSC as long as the constant is defined as a text value. |
When you pass more than one argument, you can access the arguments in order from the list of arguments.
Minitab Session Command | Value in Python | Usage |
---|---|---|
|
|
This case is an example of passing multiple
Args, where you would
access them by using the following functions in
Python:
|
File | Description |
---|---|
test.py | A sample Python script that is used throughout this guide. When you pass arguments to the script, the results include a list of the values of the arguments. When you run the script with the argument "ArgToBePrintedToStdErr", the script writes the name of the argument to the stderr file. When you run the script with the argument "ArgToBePrintedToStdOut", the script writes the name of the argument to the stdout file. Use the subcommands that follow to control whether the contents of these files appear in Minitab's Output pane. |
stderr
) console output in the Output pane in Minitab.
The stderr console output is where you see Python error messages when you run
your code in a Python integrated development environment, although you can use
Python to put other results in the stderr file. For example, by default:
PYSC "test.py" "ArgToBePrintedToStdErr".
Produces the following results that include the stderr console
output:
PYSC "test.py" "ArgToBePrintedToStdErr";
NOSERR.
The session commands produce the following results:
stdout
) in the Output pane in Minitab. The
stdout
is where you would see the
results of commands like
print()
in a Python integrated
development environment. For example, by default:
PYSC "test.py" "ArgToBePrintedToStdOut".
Produces the following results that exclude the
stdout
:
stdout
:
PYSC "test.py" "ArgToBePrintedToStdOut";
SOUT.
The session commands produce the following results:
File | Description |
---|---|
test.py | A sample Python script that is used throughout this guide. When you pass arguments to the script, the results include a list of the values of the arguments. |
PYEXEC.MTB | A sample Minitab exec file that includes the session commands to run the test.py script with 2 arguments. |
Execs are text files that contain Minitab session commands. You can include the PYSC command that runs Python in a Minitab exec. With exec files, you can easily run commands without re-typing them, and you can assign the exec to a custom button in Minitab. For more information about Minitab execs, go to Minitab Macros Help. To run an exec, choose .
PYSC "test.py" "Arg1" "Arg2"
To run the
Python script with the exec, use the
following steps:
If you have a Minitab exec file, you can create a custom button or menu that runs the exec. For general information on how to customize the interface in Minitab, go to Customize menus, toolbars and shortcut keys.
In addition to customizing Minitab's interface, you can use a COM-compliant language to create custom dialog boxes and analyses. For information on how to customize Minitab through COM, go to Minitab Automation.
Press Ctrl + Alt + Delete to open the Microsoft® Windows Task Manager. Then, end the Python process.