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

eval ? ['LBBW': checked]

P: n/a
You can use the exec statement (note that I set the if-condition to
1=true for the example, and I used different names for outer and inner
loop indexes):
for index in range(1,4): .... list = []
.... for inner in range(1,7):
.... if 1:
.... list.append(inner)
.... foo = "list_" + str(index) + "= list"
.... exec foo
.... list_1 [1, 2, 3, 4, 5, 6] list_2 [1, 2, 3, 4, 5, 6] dir() ['__builtins__', '__doc__', '__name__', 'foo', 'index', 'inner', 'list',
'list_1', 'list_2', 'list_3'] globals()

{'list_3': [1, 2, 3, 4, 5, 6], 'index': 3, 'list_1': [1, 2, 3, 4, 5, 6],
'list_2': [1, 2, 3, 4, 5, 6], '__builtins__': <module '__builtin__'
(built-in)>, 'list': [1, 2, 3, 4, 5, 6], 'inner': 6, '__name__':
'__main__', 'foo': 'list_3= list', '__doc__': None}


I'm trying to use eval (is the right function? ) to generate empty lists
with different names(es. list_1, list_2, list_3, ...) in a loop similar

for index in range(1,4):
for index in range(1,7):
if <condition>:

I am not a programmer as you probably see from the code and I do not
even know if this is the right approach to do that in Python (I used
this structure with Matlab that I want now to dismiss ...)

Any help?


| LBBW Security Information |
| - Die Nachricht war weder verschluesselt noch digital unterschrieben |
Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene
Empfänger sind oder falls diese E-Mail irrtümlich an Sie adressiert wurde,
verständigen Sie bitte den Absender sofort und löschen Sie die E-Mail
sodann. Das unerlaubte Kopieren sowie die unbefugte Übermittlung sind nicht
gestattet. Die Sicherheit von Übermittlungen per E-Mail kann nicht
garantiert werden. Falls Sie eine Bestätigung wünschen, fordern Sie bitte
den Inhalt der E-Mail als Hardcopy an.

The contents of this e-mail are confidential. If you are not the named
addressee or if this transmission has been addressed to you in error,
please notify the sender immediately and then delete this e-mail. Any
unauthorized copying and transmission is forbidden. E-Mail transmission
cannot be guaranteed to be secure. If verification is required, please
request a hard copy version.

Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.