I am pretty new to the Jython world, I have a need to create the jvm custom properties but i am king on struck at array. please provide expertise suggestion..

Here is my code snippet :

### JVM CUSTOM PROPERTIES SCRIPT ###

fileOpen = open("/tmp/jvmname.props", "r")
fileRead = fileOpen.read()
server = AdminConfig.getid("/Server:"+fileRead+"/")
jvm = AdminConfig.list('JavaVirtualMachine', server)
# print jvm
lineSeparator = java.lang.System.getProperty('line.separator')
arrayJVMs = jvm.split(lineSeparator)
jvmc = arrayJVMs[0]
attr = []
jvmCustomProperties0 = [['user.timezone', 'GMT'],['ecom.stub.enable', 'True']]
for test in jvmCustomProperties0:
print test[0]


I am getting syntax error, I need to extract the test[0] = 'user.timezone' , test[1] = 'GMT' so....on, Using for loop process i want to add more than 1 jvm custom property.

I am pretty new to the Jython world, I have a need to create the jvm custom properties but i am king on struck at array. please provide expertise suggestion..

Here is my code snippet :
-- snip, snip --
I am getting syntax error, I need to extract the test[0] = 'user.timezone' , test[1] = 'GMT' so....on, Using for loop process i want to add more than 1 jvm custom property.

Daniweb uses BBCode and the relavant tags for program code is easy to put in message by fist pushing (code), then pasting the code.

For example:

### JVM CUSTOM PROPERTIES SCRIPT ###

fileOpen = open("/tmp/jvmname.props", "r")
fileRead = fileOpen.read()
server = AdminConfig.getid("/Server:"+fileRead+"/")
jvm = AdminConfig.list('JavaVirtualMachine', server)
# print jvm
lineSeparator = java.lang.System.getProperty('line.separator')
arrayJVMs = jvm.split(lineSeparator)
jvmc = arrayJVMs[0]
attr = []
jvmCustomProperties0 = [['user.timezone', 'GMT'],['ecom.stub.enable', 'True']]
for test in jvmCustomProperties0:
    print test[0]

Do yo mean this:

jvmCustomProperties0 = [['user.timezone', 'GMT'],['ecom.stub.enable', 'True']]
for subitem in (item for sublist in jvmCustomProperties0
                for item in sublist):
    print('%r' % subitem)
""" Output:
'user.timezone'
'GMT'
'ecom.stub.enable'
'True'
"""

Yes, Some thing like that But I did not understood the syntax of

for subitem in (item for sublist in jvmCustomProperties0
for item in sublist):

You can do it also as:

jvmCustomProperties0 = [['user.timezone', 'GMT'],['ecom.stub.enable', 'True']]
for items in jvmCustomProperties0:
    for subitem in items:
        print('%r' % subitem)
            
""" Output:
'user.timezone'
'GMT'
'ecom.stub.enable'
'True'
"""

If you prefer nested expressions to generators (http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#generator-expressions-1).

Generators are usually preferred method though in Python, so it good to practise using them. You could really benefit reading Python Is Not Java: http://dirtsimple.org/2004/12/python-is-not-java.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.