<div class="MsoNormal">Thank you all for your suggestions.</div>    <div class="MsoNormal"><o:p></o:p>The purpose of this script to read values for initialization of a class that calls functions from another software program for chemically reacting flows (<a href="http://www.cantera.org/">www.cantera.org</a>). I have around 25 input variables with distinct variable names (don’t follow any patterns) with 5 strings (i.e., last five variables that contain chemical species names). Currently, I use a csv file to provide the initial values.<span style="">&nbsp; </span>I hope this answers your questions.</div>  Lex<br><br><b><i>Michael Langford &lt;mlangford.cs03@gtalumni.org&gt;</i></b> wrote:<blockquote class="replbq" style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"> I'd like to be clear, this isn't a clean thing for the middle of a big<br>program. I was thinking the entire time I was testing it "I wonder why<br>anyone would need to do
 this...."<br><br>But if you have a python program you'd probably call a script, used<br>for one simple task, it can be appropriate (with Kent's catch on the<br>globals/local thing). I assumed you were using your approach for<br>something like that. (would you tell us what you're doing this for<br>btw? The suspense ... :o))<br><br>If you're doing something like multivariable analysis or something<br>else that you would do in software like maple, this approach can<br>greatly simplify the notation over the list/dict approach.<br><br>If you're not using python as a huge substitute for a math solver,<br>then avoid what I said like the plague and use a dict.<br><br>          --Michael<br><br>On 1/15/08, Michael Langford <mlangford.cs03@gtalumni.org> wrote:<br>&gt; Accidentally cut off a 0 there...<br>&gt; Think about using ConfigParser instead of your csv. Doug Hellman wrote<br>&gt; a good article on that:<br>&gt;
 http://blog.doughellmann.com/2007/04/pymotw-configparser.html<br>&gt;<br>&gt; But if you really want to load your data this way, this will work:<br>&gt;<br>&gt; for subscript,line in enumerate(file("file.csv")):<br>&gt;      s = line.split(",")[1]<br>&gt;      try:<br>&gt;              f = float(s)<br>&gt;              locals()["x%i" % subscript]=f<br>&gt;      except:<br>&gt;              locals()["x%i" % subscript]=s<br>&gt;<br>&gt; print x1<br>&gt; print x0<br>&gt;<br>&gt; On Jan 15, 2008 3:47 PM, Michael Langford <mlangford.cs03@gtalumni.org> wrote:<br>&gt; &gt; for subscript,line in enumerate(file("file.csv")):<br>&gt; &gt;      s = line.split(",")[1]<br>&gt; &gt;      try:<br>&gt; &gt;              f = float(s)<br>&gt; &gt;              locals()["x%i" % subscript]=f<br>&gt; &gt;      except:<br>&gt; &gt;              locals()["x%i" % subscript]=s<br>&gt; &gt;<br>&gt; &gt; print x1<br>&gt; &gt; print x<br>&gt; &gt;<br>&gt; &gt; On Jan 15, 2008 3:26 PM, lechtlr
 <lechtlr@yahoo.com> wrote:<br>&gt; &gt;<br>&gt; &gt; &gt; I want to read an input file (file.csv) that has two columns. I want to read<br>&gt; &gt; &gt; 2nd column and assign variables that are strings and floats. Currently, I<br>&gt; &gt; &gt; use the following split() function to read from the input file and create a<br>&gt; &gt; &gt; list, and then assign each element to a variable.<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; I am wondering there is any other easier (and elegant) way of doing this ?<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; data = []<br>&gt; &gt; &gt; for line in open("file.csv"):<br>&gt; &gt; &gt;      columns = line.split(',')<br>&gt; &gt; &gt;      data.append([columns[1]])<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; This script returns, say:<br>&gt; &gt; &gt; data = [ ['20.0'], ['0.34'], ................,[ 'a:0.20, b:0.30, c:0.50' ]]<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Then, I assign to a set of variables, say:<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; x1 = float(data[0][0]) ;
 x2 = float(data[1][0]);.............;xn =<br>&gt; &gt; &gt; data[-1][0]<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Thanks,<br>&gt; &gt; &gt; Lex<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;  ________________________________<br>&gt; &gt; &gt; Never miss a thing. Make Yahoo your homepage.<br>&gt; &gt;<br>&gt; &gt; &gt; _______________________________________________<br>&gt; &gt; &gt; Tutor maillist  -  Tutor@python.org<br>&gt; &gt; &gt; http://mail.python.org/mailman/listinfo/tutor<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; --<br>&gt; &gt; Michael Langford<br>&gt; &gt; Phone: 404-386-0495<br>&gt; &gt; Consulting: http://www.RowdyLabs.com<br>&gt; &gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt; --<br>&gt; Michael Langford<br>&gt; Phone: 404-386-0495<br>&gt; Consulting: http://www.RowdyLabs.com<br>&gt;<br><br><br>--
 <br>Michael Langford<br>Phone: 404-386-0495<br>Consulting: http://www.RowdyLabs.com<br></lechtlr@yahoo.com></mlangford.cs03@gtalumni.org></mlangford.cs03@gtalumni.org></blockquote><br><p>&#32;
      <hr size=1>Looking for last minute shopping deals? <a href="http://us.rd.yahoo.com/evt=51734/*http://tools.search.yahoo.com/newsearch/category.php?category=shopping"> 
Find them fast with Yahoo! Search.</a>