source: pyutilib.workflow/trunk/doc/workflow/examples/example1c.py @ 2003

Revision 2003, 634 bytes checked in by wehart, 4 years ago (diff)

An update to use the argparse.ArgumentParser? instead of the
optparse.OptionParser? to parser command-line arguments. The argparse
package is being included in future Python releases, and this package
supports the definition of subcommands.

Line 
1import pyutilib.workflow
2
3class TaskAA(pyutilib.workflow.Task):
4
5    def __init__(self, *args, **kwds):
6        """Constructor."""
7        pyutilib.workflow.Task.__init__(self, *args, **kwds)
8        self.inputs.declare('x')
9        self.inputs.declare('y')
10        self.parser.add_argument('--x', dest='x', type=int)
11        self.parser.add_argument('--y', dest='y', type=int)
12        self.outputs.declare('z')
13
14    def execute(self):
15        """Compute the sum of the inputs."""
16        self.z = self.x + self.y
17
18# @ex:
19AA = TaskAA()
20w = pyutilib.workflow.Workflow()
21w.add(AA)
22w.set_options(['--x=1', '--y=3'])
23print w(y=4)
24# @:ex
25
Note: See TracBrowser for help on using the repository browser.