Scripting Language | Jacl | Jython |
---|---|---|
Scripting Example | wsadmin>set x {1 2 3 4} 1 2 3 4 wsadmin>set y [linsert $x 3 999] 1 2 3 999 4 wsadmin>puts $x 1 2 3 4 wsadmin>puts $y 1 2 3 999 4 |
wsadmin>x = [1,2,3,4] wsadmin>y = x.insert(3,999) wsadmin>print x [1, 2, 3, 999, 4] wsadmin>print y None |
Explanation | The Jacl linsert operation leaves the original list unchanged and returns a new list. | The Jython list.insert operation changes the original list and does not return an output list. |
JACL: set x {1 2 3} JACL: set x [linsert $x end 4] ==> JYTHON: x = [1, 2, 3] JYTHON: x = x.insert( len(x), 4 ) #?PROBLEM? (jacl 123) Jython \ #list.insert does not produce #any output value ('None')
JYTHON: x = [1, 2, 3] JYTHON: x = x.insert( len(x), 4 ) JYTHON: print x NoneThe problem is the Jython list.insert does not produce any output value. In this scripting example, the x.insert( len(x), 4 ) returns a NONE value and becomes assigned to the left value of x. To correct the problem you need to remove this extra assignment statement. The manually corrected list.insert statement for the Jython script is as follows:
JYTHON: x = [1, 2, 3] JYTHON: x.insert( len(x), 4 ) #manually corrected
The following is an example of running the manually corrected Jython script:
JYTHON: x = [1, 2, 3] JYTHON: x.insert( len(x), 4 ) JYTHON: print x [1, 2, 3, 4]