Thank you all for your suggestions.
The purpose of this script to read values for initialization of a class
that calls functions from another software program for chemically reacting
flows (www.cantera.org). I have around 25 input variables with distinct
variable names (dont follow any pa
I'd like to be clear, this isn't a clean thing for the middle of a big
program. I was thinking the entire time I was testing it "I wonder why
anyone would need to do this"
But if you have a python program you'd probably call a script, used
for one simple task, it can be appropriate (with Kent'
lechtlr wrote:
> I want to read an input file (file.csv) that has two columns. I want
> to read 2nd column and assign variables that are strings and floats.
> Currently, I use the following split() function to read from the input
> file and create a list, and then assign each element to a variab
Michael Langford wrote:
> for subscript,line in enumerate(file("file.csv")):
> s = line.split(",")[1]
> try:
>f = float(s)
>locals()["x%i" % subscript]=f
> except:
>locals()["x%i" % subscript]=s
Don't do this!
For one thing, writing to locals() d
Accidentally cut off a 0 there...
Think about using ConfigParser instead of your csv. Doug Hellman wrote
a good article on that:
http://blog.doughellmann.com/2007/04/pymotw-configparser.html
But if you really want to load your data this way, this will work:
for subscript,line in enumerate(file("f
for subscript,line in enumerate(file("file.csv")):
s = line.split(",")[1]
try:
f = float(s)
locals()["x%i" % subscript]=f
except:
locals()["x%i" % subscript]=s
print x1
print x
On Jan 15, 2008 3:26 PM, lechtlr <[EMAIL PROTECTED]> wrote:
> I wa
lechtlr wrote:
> I want to read an input file (file.csv) that has two columns. I want to
> read 2nd column and assign variables that are strings and floats.
> Currently, I use the following split() function to read from the input
> file and create a list, and then assign each element to a variab
Python has a cvs module that will make this slightly more elegant
http://docs.python.org/lib/module-csv.html
j
On Jan 15, 2008 2:26 PM, lechtlr <[EMAIL PROTECTED]> wrote:
> I want to read an input file (file.csv) that has two columns. I want to
> read 2nd column and assign variables that are st