By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,835 Members | 964 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,835 IT Pros & Developers. It's quick & easy.

Possible to have multiple loop variables?

P: n/a
I don't know why I thought this would work, but I would like to have 3
variables in my for loop per iteration. Those familiar will know that
this

ms1 = {'managed1':7019:8020,'managed2':7020:8021}
for m, lp, ssl_lp in ms1.items():
managedServer = create(m,'Server')
print 'creating managed server '+m
managedServer.setListenAddress('147.191.71.70')
managedServer.setListenPort(lp)
managedServer.setEnabled(0)
cd('SSL/cgServer')
managedServer.setEnabled(1)
managedServer.setListenPort(ssl_lp)
managedServer.setCluster(clus1)

causes

File "/export/third-party/etsbea/home/etsbea/tests/wlst/
createcluster.py", line 9
ms1 = {'managed1':7019:8020,'managed2':7020:8021}
^
SyntaxError: invalid syntax
How would I set up the ms1 array such that I can use three items per
object?

Thanks, - Dave
Jul 30 '08 #1
Share this Question
Share on Google+
1 Reply

P: n/a
On Wed, 30 Jul 2008 10:49:58 -0700, laredotornado wrote:
I don't know why I thought this would work, but I would like to have 3
variables in my for loop per iteration. Those familiar will know that
this

ms1 = {'managed1':7019:8020,'managed2':7020:8021} for m, lp, ssl_lp in
ms1.items():
managedServer = create(m,'Server')
print 'creating managed server '+m
managedServer.setListenAddress('147.191.71.70')
managedServer.setListenPort(lp)
managedServer.setEnabled(0)
cd('SSL/cgServer')
managedServer.setEnabled(1)
managedServer.setListenPort(ssl_lp)
managedServer.setCluster(clus1)

causes

File "/export/third-party/etsbea/home/etsbea/tests/wlst/
createcluster.py", line 9
ms1 = {'managed1':7019:8020,'managed2':7020:8021}
^
SyntaxError: invalid syntax
How would I set up the ms1 array such that I can use three items per
object?
`ms1` is a dictionary and not an array. You could use a tuple as value:

In [5]: ms1 = {'managed1': (7019, 8020), 'managed2': (7020, 8021)}

In [6]: for a, (b, c) in ms1.iteritems():
...: print a, b, c
...:
managed1 7019 8020
managed2 7020 8021

Ciao,
Marc 'BlackJack' Rintsch
Jul 30 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.