<!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
<title>SPARC Architectural Model: User Commands
</title>
<body bgcolor=
"#FFFFFF" LANG=
"en-US">
<div STYLE=
"margin-bottom: 0cm"></div>
run-python-file - execute python script file
run-python-file
<i>filename
</i>
Read Python code from
<i>filename
</i>. Any definitions are entered
level name-space in the Python environment. This command can be used to
start Python scripts inside simulation.
SAM provides a python method, sam.ui_register(), to register python
methods with the user interface.
This method can be used to add arbitrary functionality to the SAM UI.
The ui_exec() method allows SamUI commands to be executed from python.
The sam python object provides the following methods to access the
SamUI, registers and unregister methods as commands with the SamUI.
<th>Method Name
</th><th>Description
</th>
<td>ui_exec (
"<i>cmd</i>")
</td>
<td>Sends
<i>cmd
</i> to the SamUI.
</td>
<td>ui_register
(
"<i>cmd_name</i>",
"<i>help_string</i>",
<i>cmd_function
<i>)
</td>
<td>Registers the python function
<i>cmd_function
</i> with the SamUI
as
"<i>cmd_name</i>". The commands help string is
"<i>help_string</i>".
</td>
<td>ui_unregister (
"<i>cmd_name</i>")
</td>
<td>Unregisters the command registered with the SamUI,
Here is an example that registers the python method
<code>echo()
</code> as
"py_echo".
print argv
<br>
sam.ui_register(
"py_echo",
"Prints its arguments", echo)
<br>
Here is another example that runs python code from the SamUI:
cmd =
" ".join(argv[
1:])
<br>
exec(cmd)
<br>
print
"ERROR"<br>
sam.ui_register(
"exec_py",
"exec_py runs python code",exec_py)
Now from the SamUI, one can type:
exec_py print
"xyz is %d" % xyz
<br>
<ul><a href=
"cmd_run-cmd-file.html">run-command-file
</a></ul>
<ul><a href=
"http://www.python.org">python
</a></ul>