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
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
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() doesn't always
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 variable.
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's