473,548 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

eval ? ['LBBW': checked]

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(inn er)
.... 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
to:

for index in range(1,4):
list=[]
for index in range(1,7):
if <condition>:
list.append(1)
foo='list_'+str (index)+'=list'
eval(foo)

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?
Thanks
angelo

--
http://mail.python.org/mailman/listinfo/python-list

+----------------------------------------------------------------------+
| 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
0 1051

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2023
by: Jean-Sébastien Bolduc | last post by:
Hello, I would like to associate a local namespace with a lambda function. To be more specific, here is exactly what I would want: def foo(): a = 1 f = lambda x : a*x return f
0
1652
by: Holger Joukl | last post by:
Hi, what version of python are you using? I got the same error when invoking a customized, 2-year-old version of distutils with python 2.3.3 (instead of 1.5.2, as before). Reason is code in dist.py, using dir() to look up the attributes of a class instance. But dir() nowadays also returns the class methods, __doc__ etc. Changing this in...
9
8454
by: HikksNotAtHome | last post by:
This is a very simplified example of an Intranet application. But, is there an easier (or more efficient) way of getting the decimal equivalent of a fraction? The actual function gets the select values, this one is a simplified version where its passed. function checkIt(selVal){ valueInDec1 = eval(selVal); //do some calculations here...
7
4091
by: Reply Via Newsgroup | last post by:
This might sound sad... someone requesting a disertation on the 'eval' statement... but... I've been reading someone else's post - they had a huge calander like script and a handful of folk cursed the script and special attention was thrown at the fact the script used eval alot. I don't use eval alot in my scripts - but I do use it - and...
1
309
by: Chris | last post by:
I have a class method that returns a DataSet. I use bind this to my Repeater control. Inside the Repeater i have <ItemTemplate> <li><%# DataBinder.Eval(Container.DataItem, "name") %> <%# DataBinder.Eval(Container.DataItem, "enabled") %></li> </ItemTemplate>
6
23953
by: Dan | last post by:
I need to be able to execute a command that is defined in a string. In VBScript, I can do it with the Eval function. How can I do it in VB.Net? I need something like: Dim x As Integer Eval("x = 3") MsgBox x ' Should show a popup with 3 as the message I'm in desperate need of this function. There must be something similar in
21
8503
by: hemant.singh | last post by:
Hello all, I am try'g to send window.location.href to the server script who will generate dynamic javascript according to the referral name comg in as param Now bcz <script language="javascript" src="NO JAVASCRIPT CAN BE USED HERE" /> So I am see'g If I can use eval todo something what I am doing I have tried almost everything,...
3
13701
by: idletask | last post by:
I have an SQLDataSource control, which is bound to an ASP.net 2.0 GridView control. It outputs a list of documents that a user can check in or check out of the database. In my gridview, I have a column called "checked out" which is bound to a column in my database, called "checkedout". A zero means no, and a one means yes (that the...
10
494
by: Gordon | last post by:
I have a script that creates new objects based on the value of a form field. Basically, the code looks like this. eval ('new ' + objType.value + '(val1, val2, val3'); objType is a select with the different types of objects you can create as values. I really don't like using eval, and it's causing problems, like if I do something like...
0
7512
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7707
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7951
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7466
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7803
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5362
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5082
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3475
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
751
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.