- Table of Contents
-
- 01-Fundamentals Command Reference
- 00-Preface
- 01-CLI commands
- 02-RBAC commands
- 03-Login management commands
- 04-FTP and TFTP commands
- 05-File system management commands
- 06-Configuration file management commands
- 07-Software upgrade commands
- 08-GIR commands
- 09-Preprovisioning commands
- 10-Target configuration management commands
- 11-Device management commands
- 12-Tcl commands
- 13-Python commands
- 14-License management commands
- Related Documents
-
Title | Size | Download |
---|---|---|
13-Python commands | 59.41 KB |
Contents
Python commands
Python2 commands
exit()
Use exit() to exit the Python2 shell.
Syntax
exit()
Views
Python2 shell
Predefined user roles
network-admin
Usage guidelines
To return to user view from the Python2 shell, you cannot use the quit command. You must use the exit() command.
Examples
# Exit the Python2 shell.
>>> exit()
<Sysname>
python
Use python to enter the Python2 shell.
Syntax
python
Views
User view
Predefined user roles
network-admin
Usage guidelines
In the Python2 shell, you can use the following items:
· Python 2.7 commands.
· Python 2.7 standard API.
· Comware 7 extended API.
Examples
# Enter the Python2 shell.
<Sysname> python
Python 2.7.18 (default)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
python filename
Use python filename to execute a Python2 script.
Syntax
python filename [ param ]
Views
User view
Predefined user roles
network-admin
Parameters
filename: Specifies the name of a Python2 script on a storage medium of the device. The script name is case sensitive and must use the extension .py. The extension .py is case insensitive.
param: Specifies the parameters to be passed to the script. To enter multiple parameters, use spaces as the delimiter.
Usage guidelines
You cannot perform any operations while you are executing a Python2 script.
Make sure the statements in the script meet the syntax requirements. The system stops executing a Python2 script if it finds a statement with syntax errors.
When executing a script, the system uses the defaults for interactive statements. The system does not stop for human input.
Examples
# Execute Python2 script test.py.
<Sysname> python test.py 1 2
['/flash:/test.py', '1', '2']
Python3 commands
exit()
Use exit() to exit the Python3 shell.
Syntax
exit()
Views
Python3 shell
Predefined user roles
network-admin
Usage guidelines
To return to user view from the Python3 shell, you cannot use the quit command. You must use the exit() command.
Examples
# Exit the Python3 shell.
>>> exit()
<Sysname>
python3
Use python to enter the Python3 shell.
Syntax
python3
Views
User view
Predefined user roles
network-admin
Usage guidelines
In the Python3 shell, you can use the following items:
· Python 3.11 commands.
· Python 3.11 standard API.
· Comware 7 extended API.
Examples
# Enter the Python3 shell.
<Sysname> python3
Python 3.11.0 (default)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
python3 filename
Use python3 filename to execute a Python3 script.
Syntax
python3 filename [ param ]
Views
User view
Predefined user roles
network-admin
Parameters
filename: Specifies the name of a Python3 script on a storage medium of the device. The script name is case sensitive and must use the extension .py. The extension .py is case insensitive.
param: Specifies the parameters to be passed to the script. To enter multiple parameters, use spaces as the delimiter.
Usage guidelines
You cannot perform any operations while you are executing a Python3 script.
Make sure the statements in the script meet the syntax requirements. The system stops executing a Python3 script if it finds a statement with syntax errors.
When executing a script, the system uses the defaults for interactive statements. The system does not stop for human input.
Examples
# Execute Python3 script test.py.
<Sysname> python3 test.py 1 2
['/flash:/test.py', '1', '2']