Search code examples
pythonoracleweblogicwlst

Take error on wlst console when work with statements or loops


Not able to make loop and statement after it.

Example:

wls:/ADMIN_server/serverConfig> serverRuntime()
Location changed to serverRuntime tree. This is a read-only tree with ServerRuntimeMBean as the root.
For more help, use help(serverRuntime)

wls:/ADMIN_server/serverRuntime> dsMBeans = cmo.getJDBCServiceRuntime().getJDBCDataSourceRuntimeMBeans()
wls:/ADMIN_server/serverRuntime> ds_name = "ADMIN_DB"
wls:/ADMIN_server/serverRuntime> for ds in dsMBeans:
...
Traceback (innermost last):
  (no code object) at line 0
  File "<console>", line 2
SyntaxError: invalid syntax

Not sure is it need to import something before that options like and for that reason not able to make loop with statement:

import time
import sys

Solution

  • You shouldn't need to import anything specific to have access to the looping mechanism in WLST. For instance, try the following:

    slist=range(1,4)
    for i in slist: print 'i = ' + str(i);
    

    The result should be:

    i = 1
    i = 2
    i = 3
    

    The syntax of your statements after the for loop are probably causing a problem in your python script OR if you are manually typing the commands in, you need to make sure you put a space after ... for it to interpret the next line like:

    wls:/offline> j = 0
    wls:/offline> while j<4:
    ... print 'j = ' + str(j)
    ... j = j + 1
    ...
    jms 0
    jms 1
    jms 2
    jms 3
    

    Notice it is very important to type in a space character after ... or you will have the invalid syntax error.