Yes, you can define the Python classes in a separate .py file
(particularly if you wanted to use them in multiple STAX jobs) and use the
SCRIPTFILE option to specify the fully qualified name of the .py file. You
can also optionally use the SCRIPTMACHINE option to specify the machine
where the .py file is located if it's located. These options are
discussed as follows in the "EXECUTE" Request Syntax section in the STAX
User's Guide as follows. Also, the STAX Monitor allows you to specify the
SCRIPTFILE and SCRIPTMACHINE options via its GUI when submitting a STAX
job via the STAX Monitor.
SCRIPTFILE specifies the fully qualified name of a file containing Python
code to be executed. This is like a <script> element in root <stax>
element in the XML document, but defined when submitting an execute
request, rather than within the XML document. Note that a SCRIPTFILE
parameter specified in an execute request will be executed by the STAX
service after any "global" <script> elements (that is, those contained
directly within the root <stax> element), but before any SCRIPT parameters
are executed. Thus, you can override the value of a variable specified in
a global <script> element by using a SCRIPTFILE parameter in the execute
request. You may specify as many SCRIPTFILE parameters as needed. This
option will resolve STAF variables.
SCRIPTFILEMACHINE specifies the endpoint for the machine where the
SCRIPTFILE(s) are located. If not specified, it defaults to the value
specified for MACHINE. If a MACHINE option was not specified, it assumes
the script file(s) are on the machine submitting the STAX EXECUTE request.
This option will resolve STAF variables.
For example:
STAF staxMachine STAX EXECUTE FILE C:/tests/jobA.xml SCRIPTFILE
C:/tests/init1.py WAIT
Note that STAX uses Jython 2.1 to run Python code. Jython 2.1 is based on
Python 2.1. Jython 2.1 cannot execute Python code that uses functions
that were provided in later versions of Python, such as Python 2.2. See
section "Appendix F: Jython and CPython Differences" in the STAX User's
Guide for more information on differences between Jython and Python.
Or, you could define Python classes in a <script> element contained
directly within the root <stax> element so that they'll be accessible by
any function defined in your STAX job. All script elements contained in
the root stax element are initialized at the beginning of the job, as each
is encountered in sequential order, regardless of their placement within
the stax element, and are accessible throughout the job (like global
variables).
For example:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "stax.dtd">
<stax>
<defaultcall function="main"/>
<script>
# Define Python class
</script>
<script>
# Define another Python class if desired
</script>
<function name="main">
...
</function>
<function name="whatever">
...
</function>
</stax>
--------------------------------------------------------------
Sharon Lucas
IBM Austin, [EMAIL PROTECTED]
(512) 838-8347 or Tieline 678-8347
"Ahmed Mostafa" <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]
05/14/2008 07:01 AM
To
STAF <[email protected]>
cc
Subject
[staf-users] [STAX] Python best practice: class vs. dictionaries
Hello
Where to define a Python class in order to be able to use in any of my
STAX functions? Can I define it in a separate Python script file and
include it within my STAX job definition?
I referred to this.
Thanks
--
Ahmed Mostafa
0123919750
[EMAIL PROTECTED]
Software Developer
IBM Egypt, Cairo Technology Development Center
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
staf-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/staf-users
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
staf-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/staf-users